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

Added flatMapK to FreeT #3235

Merged
merged 2 commits into from
Feb 25, 2020
Merged

Conversation

djspiewak
Copy link
Member

The analogous function on Free is simply foldMap, but FreeT has an extra (monadic) suspension functor which cannot be manipulated through the same mechanism. mapK already exists; this simply provides a way of doing a mapK-like transformation where the resulting N is itself a FreeT. This can be useful when you want to manipulate the structure of the interpretation in a composable fashion.

@codecov-io
Copy link

codecov-io commented Dec 31, 2019

Codecov Report

Merging #3235 into master will increase coverage by 0.06%.
The diff coverage is 0%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#scala_version_212 93.35% <0%> (-0.03%) ⬇️
#scala_version_213 92.89% <0%> (+0.09%) ⬆️
Impacted Files Coverage Δ
free/src/main/scala/cats/free/FreeT.scala 89.41% <0%> (-1.26%) ⬇️
core/src/main/scala/cats/syntax/group.scala 0% <0%> (-75%) ⬇️
...in/scala/cats/data/IndexedReaderWriterStateT.scala 95.19% <0%> (-1.81%) ⬇️
core/src/main/scala/cats/data/ContT.scala 100% <0%> (ø) ⬆️
core/src/main/scala/cats/data/WriterT.scala 91.26% <0%> (ø) ⬆️
...ore/src/main/scala/cats/data/NonEmptyMapImpl.scala 97.5% <0%> (ø) ⬆️
core/src/main/scala/cats/instances/list.scala 100% <0%> (ø) ⬆️
core/src/main/scala/cats/syntax/list.scala 100% <0%> (ø) ⬆️
core/src/main/scala/cats/data/NonEmptySet.scala 97.64% <0%> (ø) ⬆️
...rc/main/scala/cats/laws/ApplicativeErrorLaws.scala 100% <0%> (ø) ⬆️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f44f251...3d9303a. Read the comment docs.

LukaJCB
LukaJCB previously approved these changes Jan 2, 2020
* 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] = {
Copy link
Contributor

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 givens, 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.

Copy link
Member Author

@djspiewak djspiewak Feb 4, 2020

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.

@travisbrown travisbrown added this to the 2.2.0-M1 milestone Feb 24, 2020
@travisbrown
Copy link
Contributor

@LukaJCB I think you 👍'd this in January but I can't tell from this GitHub interface—do you mind taking a quick look?

Copy link
Member

@LukaJCB LukaJCB left a 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 👍

@travisbrown travisbrown merged commit 2e12f4d into typelevel:master Feb 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants