-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Added flatMapK to FreeT #3235
Added flatMapK to FreeT #3235
Conversation
…t's simply foldMap)
Codecov Report
@@ Coverage Diff @@
## master #3235 +/- ##
==========================================
+ Coverage 93.04% 93.11% +0.06%
==========================================
Files 376 378 +2
Lines 7407 7578 +171
Branches 200 194 -6
==========================================
+ Hits 6892 7056 +164
- Misses 515 522 +7
Continue to review full report at Codecov.
|
* Modify the context `M` using the transformation `mn`, flattening the free | ||
* suspensions into the outer. | ||
*/ | ||
def flatMapK[N[_]: Monad](mn: M ~> FreeT[S, N, *])(implicit S: Functor[S]): FreeT[S, N, 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 think we should try to avoid mixing context bounds and implicit parameter sections, in part because it's confusing (there's a whole subgenre of Stack Overflow questions related to this), but also because in Dotty context bounds will desugar to given
s, which will have slightly different semantics.
Also it seems like this should follow the rule of thumb that the order of constraints should follow the order the types appear in—so:
def flatMapK[N[_]](mn: M ~> FreeT[S, N, *])(implicit S: Functor[S], N: Monad[N]): FreeT[S, N, A]
Which is the opposite order of what the current code desugars to.
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 don't mind changing it. I mix context bounds all the time, but obviously if Dotty is changing the semantics then I should probably break that habit.
@LukaJCB I think you 👍'd this in January but I can't tell from this GitHub interface—do you mind taking a quick look? |
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.
Looks good to me 👍
The analogous function on
Free
is simplyfoldMap
, butFreeT
has an extra (monadic) suspension functor which cannot be manipulated through the same mechanism.mapK
already exists; this simply provides a way of doing amapK
-like transformation where the resultingN
is itself aFreeT
. This can be useful when you want to manipulate the structure of the interpretation in a composable fashion.