Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OptionT.fromF #659

Closed
lambdista opened this issue Nov 16, 2015 · 7 comments
Closed

Add OptionT.fromF #659

lambdista opened this issue Nov 16, 2015 · 7 comments

Comments

@lambdista
Copy link
Contributor

I noticed that the 0.3.0 version includes a useful OptionT.fromOption function. It lets you build an OptionT from an Option.

Wouldn't it be the case to add an OptionT.fromF that lets you build an OptionT from an Applicative F? As in:

scala> OptionT.fromF(List(8))
res1: cats.data.OptionT[List,Int] = OptionT(List(Some(8)))

Of course I'd accept suggestions for a better name than fromF.

@ceedubs
Copy link
Contributor

ceedubs commented Nov 16, 2015

Thanks for the suggestion @lambdista. Just to make sure I understand clearly, you're talking about a function that will take an F[A] and lift it into an OptionT[F, A] where we essentially map on the F[A] and wrap every A in Some, right?

If so, here are a couple thoughts:

  • I think we could get by with just a Functor and not require an Applicative.
  • I think this would essentially be liftM from MonadTrans, which we have talked about adding, but I don't think there's a GitHub issue for yet. I think it would be useful to have an OptionT-specific method like you suggest even if we add MonadTrans, because OptionT could get by with a Functor while liftM has a more constrained Monad requirement. The OptionT instance of MonadTrans could simply delegate through to this method.

@lambdista
Copy link
Contributor Author

Thanks for your answer @ceedubs. Yes, that's exactly what I mean. About your thoughts:

  • You're totally right, I think we could get by with just a Functor too.
  • Yes, it's essentially liftM from MonadTrans but, as you correctly wrote, having an OptionT-specific method would do no harm and require a less constrained Functor requirement compared to the Monad of liftM.

Let me know if you want me to add it and send a PR. Thank you.

@ceedubs
Copy link
Contributor

ceedubs commented Nov 16, 2015

I'd like this 👍. Anyone else?

I'd propose liftF as a name to parallel liftM but with Functor instead of Monad.

@non
Copy link
Contributor

non commented Nov 16, 2015

👍

@lambdista
Copy link
Contributor Author

That's great! liftF is perfect. 👍

@lambdista
Copy link
Contributor Author

Implemented, added test and updated related docs. Let me know if you want to me to change/add anything. Thank you.

non added a commit that referenced this issue Nov 17, 2015
add OptionT.liftF and update related docs and tests. Close issue #659
@ceedubs
Copy link
Contributor

ceedubs commented Nov 19, 2015

Completed by #667.

@ceedubs ceedubs closed this as completed Nov 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants