-
-
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
Add tapWithF to Kleisli #2252
Add tapWithF to Kleisli #2252
Conversation
@@ -75,6 +75,9 @@ final case class Kleisli[F[_], A, B](run: A => F[B]) { self => | |||
def tapWith[C](f: (A, B) => C)(implicit F: Functor[F]): Kleisli[F, A, C] = | |||
Kleisli(a => F.map(run(a))(b => f(a, b))) | |||
|
|||
def flatTapWith[C](f: (A, B) => F[C])(implicit F: FlatMap[F]): Kleisli[F, A, C] = |
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.
we have this function flatTap
on anything with a FlatMap, but it does not seem consistent with this:
cats/core/src/main/scala/cats/FlatMap.scala
Line 142 in ff7bd40
def flatTap[A, B](fa: F[A])(f: A => F[B]): F[A] = |
it discards the value inside the F[C]
.
I am concerned we don't have a clear meaning associated with tap
and flatTap
.
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 agree with you @johnynek, but I couldn't come up with a better name for this one (flatTapWith
felt "consistent" with the tapWith
function a couple of lines above)
I'm definitely open to suggestions on the name :)
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.
tapWithF?
We could rewrite (A, B) => F[C]
to A => (B => F[C])
if we had use F.pure on the result we could have done: A => F[B => F[C]]
Then this method could be written as ap followed by flattenF or something.
Just noodling around to think about naming.
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 like tapWithF
, thanks for the suggestion @johnynek!
I already pushed the change 👍
Codecov Report
@@ Coverage Diff @@
## master #2252 +/- ##
==========================================
+ Coverage 94.96% 94.96% +<.01%
==========================================
Files 333 333
Lines 5797 5798 +1
Branches 221 218 -3
==========================================
+ Hits 5505 5506 +1
Misses 292 292
Continue to review full report at Codecov.
|
4a2abc1
to
045c101
Compare
No description provided.