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 FlatMap#flatTap, a more principled version of the kestrel combinator. #1958

Merged
merged 1 commit into from
Oct 10, 2017
Merged

Add FlatMap#flatTap, a more principled version of the kestrel combinator. #1958

merged 1 commit into from
Oct 10, 2017

Conversation

hrhino
Copy link
Contributor

@hrhino hrhino commented Oct 9, 2017

It's a useful way of adding side-effects (as in, effects on the side) of a monadic computation.

I almost called it flatTap; I welcome opinions for or against either name.

* res3: List[Int] = List(4, 4, 4, 4)
* }}}
*/
def tapM[A, B](fa: F[A])(f: A => F[B]): F[A] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't this be on FlatMap not Monad?

@hrhino
Copy link
Contributor Author

hrhino commented Oct 9, 2017 via email

@codecov-io
Copy link

codecov-io commented Oct 9, 2017

Codecov Report

Merging #1958 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1958      +/-   ##
==========================================
+ Coverage   96.14%   96.14%   +<.01%     
==========================================
  Files         273      273              
  Lines        4535     4536       +1     
  Branches      114      119       +5     
==========================================
+ Hits         4360     4361       +1     
  Misses        175      175
Impacted Files Coverage Δ
core/src/main/scala/cats/FlatMap.scala 92.85% <100%> (+0.54%) ⬆️

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 b84015a...a5536ea. Read the comment docs.

kailuowang
kailuowang previously approved these changes Oct 10, 2017
@edmundnoble
Copy link
Contributor

I vote for flatTap :D

* res1: Char = 'a'
* }}}
* */
def forEffect[A, B](fa: F[A])(fb: F[B]): F[A] = tapM(fa)(_ => fb)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another PR in flight to move this to a Apply. I don’t think we need tapM here. Can we revert this change?

…tor.

It's a useful way of adding side-effects (as in, effects on the side)
of a monadic (flatMappish?) computation.
@hrhino
Copy link
Contributor Author

hrhino commented Oct 10, 2017

Cool. That's two for the better other name and zero opponents who have noticed that it might be changed.

@hrhino hrhino changed the title Add Monad#tapM, a more principled version of the kestrel combinator. Add FlatMap#flatTap, a more principled version of the kestrel combinator. Oct 10, 2017
@LukaJCB LukaJCB merged commit 8cce29c into typelevel:master Oct 10, 2017
@kailuowang kailuowang added this to the 1.0.0-RC1 milestone Oct 13, 2017
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.

6 participants