-
Notifications
You must be signed in to change notification settings - Fork 67
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 asRightIn, asLeftIn and asSomeIn for anyF #460
Add asRightIn, asLeftIn and asSomeIn for anyF #460
Conversation
Similar questions about how much use these would see as here |
def asRightIn[L](implicit F: Functor[F]): F[Either[L, A]] = | ||
Functor[F].map(fa)(Right(_)) | ||
|
||
def asLeftIn[R](implicit F: Functor[F]): F[Either[A, R]] = | ||
Functor[F].map(fa)(Left(_)) | ||
|
||
def asSomeIn(implicit F: Functor[F]): F[Option[A]] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was the one who added this In
postfix in the naming within FEither / FOption syntaxes, and I don't think it should be reused any-elsewhere. In the context of the mentioned syntaxes, it emphasizes the intention of applying the provided function to the value of the inner context (Either / Option). But seeing that postfix is used that way is a little bit confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking more on this I agree with you. I still feeling that we need these methods to "map and wrap" an effect F
.
What about something like mapAsRight
, mapAsLeft
and mapAsSome
.
At the end they are something like this
IO.pure(1).map(_.asRight[String])// IO[Either[String, Int]]
// with the new operator
IO.pure(1).mapAsRight[String]// IO[Either[String, Int]]
I don't know, I don't have many ideas at the moment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! I was just checking issues/PRs before proposing exactly the same thing, with the originally proposed names: asRightIn
/asLeftIn
/asSomeIn
.
Maybe you'll find my thoughts on the naming helpful. To me, these operations are performed on the value in the context of an F
, which is quite similar to mapIn
, flatMapIn
. Somehow, asRightIn
/asLeftIn
/asSomeIn
felt natural to me and I actually was a bit surprised to find out they’re missing.
So, any plans of settling on the naming and merging the PR? 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Lets get this merged, it's sat long enough, and a 2nd user wanting same thing is evidence for usefulness.
👍 from me, are you ok to merge in current state @danicheg ?
@benhutchison it's good to go! |
Hi guys! This PR adds some methods to map an
F[A]
intoF[Either[L, A]]
,F[Either[A, R]]
orF[Option[A]]
.Example
And for the naming, here a recap
What do you think ? Is there already something in place that I didn't found ? If not, do you think the name is coherent ?