Open LukaJCB opened 5 years ago
@LukaJCB What use case(s) do you have in mind for that? Tried to find a good example for a doctest, but I can't come up with something "useful" - in fact, it has rather weird behaviour for some Alternative
instances, for example List
:
Alternative[List].attemptOption(Nil) // returns List(None)
Alternative[List].attemptOption(List(2)) // returns List(Some(2), None)
So it's pretty much fs2's noneTerminate
on a List
. Option
itself seems also not very handy:
Alternative[Option].attemptOption(None) // returns Some(None)
Alternative[Option].attemptOption(Some(2)) // returns Some(Some(2))
I would see a use case for IO
(equivalent to .attempt.map(_.toOption)
), but as it has no Alternative
instance, it doesn't matter here.
If you're using mtl and have OptionT
somewhere in your stack, this would allow you to materialize the option :)
E.g. something like ReaderT[OptionT[IO, ?], R, A]
Maybe my head is a bit slow today - still can't figure out how you would use it. ReaderT[F, _, _]
has an instance of Alternative
iff F
has and OptionT
doesn't seem have any Alternative
instance (only MonoidK
). Can you maybe share a short code snippet that illustrates the use case?
Oh that'd odd, I was sure OptionT
had an Alternative
instance 🤔
Hi, I can try to help with this. Does an Alternative
instance need to be added for OptionT
then?