-
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 asIn, voidIn, leftAsIn, leftVoidIn into foption and feither. #458
Conversation
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.
Hey! I think it'd be convenient to have these suggested methods 👍🏻
@geirolz Are these operations actually being used in your codebases, or is it simply that they might be used? I'd feel more comfortable if we had examples in the wild where these would be used. As these methods demonstrate, there are many possible permutations and conversions when nested contexts are involved. How many should Mouse define, vs leaving programmers to compose the operations at the use site? It's an ambiguous question with no clearly correct answer.. But extra library surface area does come with costs - slower compile times and code completion, more crowded namespaces. |
Apologies, hit wrong button, intended to comment not close. |
Thanks for your feedback @benhutchison! My specific case was that I had a service returing Cats can't introduce these useful method, If I get it right the purpose of mouse is to add extra syntax to simplify the usage of cats. I believe that these operators could be useful in some cases. |
@benhutchison |
@danicheg I'm happy to defer to your judgment here. I don't want to get in the way of programmers factoring out repeated structure in their code; I believe it's important to keep things DRY. Mouse is the blessed place for these sorts of combinators. I just want to ensure we are harvesting actual shared structure from users, and don't verge into speculating shared structures that conceivably might be useful. @geirolz I'd have been more comfortable if the PR mentioned something about your usage of the proposed operations. Thanks for detailing the 🤔
|
Makes sense and I agree with you on this!
Basically yes,
In this case I may want to ignore the result and return another type. // some(true) => deleted
// some(false) => not-deleted
// none => not-found
def deleteTempUserInfo(userId: UserId): IO[Option[Boolean]]
// I just care if the user exists ( to return a 404 for instance ) but I don't really case about the result
val result: IO[Option[UserId]] = deleteTempUserInfo(userId).asIn(userId)
Yes but I got a case where I wanted to replace the very specific error ( Left ) with a generic HTTP one like |
OK, thanks for the explanation 👍 |
Hi guys! This PR adds some useful methods based on
mapIn
andleftMapIn
.F[Option[A]]
asIn
-> mapF[Option[A]]
toF[Option[B]]
ignoring theA
value.voidIn
-> drainF[Option[A]]
toF[Option[Unit]]
ignoring theA
value.F[Either[L, R]]
asIn
-> mapF[Either[L, R]]
toF[Either[L, B]]
ignoring theR
value.voidIn
-> drainF[Either[L, R]]
toF[Either[L, Unit]]
ignoring theR
value.leftAsIn
-> mapF[Either[L, R]]
toF[Either[B, R]]
ignoring theL
value.leftVoidIn
-> drainF[Either[L, R]]
toF[Either[Unit, R]]
ignoring theL
value.What do you think ?