-
-
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 examples for Cokleisli #1993
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1993 +/- ##
=======================================
Coverage 95.49% 95.49%
=======================================
Files 298 298
Lines 4814 4814
Branches 120 120
=======================================
Hits 4597 4597
Misses 217 217
Continue to review full report at Codecov.
|
* scala> def before(x: Int) = x + 1 | ||
* scala> def after(x: Int) = x - 1 | ||
* scala> val example : Cokleisli[Id,Int,Int] = Cokleisli((f: Id[Int]) => f.extract) | ||
* scala> example.dimap(before)(after) == 42 |
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.
Can you add what this returns here and below?
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.
Thanks @LukaJCB for the reminder, appreciate it.
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.
@johnynek thanks for the review and agree with you. Following on your lead, i've revised the examples to use NonEmptyList
instead, let me know what you think when you look at them?
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 appreciate you sending the PR. Could we find an example with M not being Id? The problem with Id is that it makes many typeclasses trivial and does not really give much of an idea what is going on.
What about M = NonEmptyList?
@johnynek thanks for the review and i agree with you. Following your suggestion, i've changed it examples to using |
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.
Thanks! I like these NEL examples. One minor suggestion below.
* scala> example.dimap(before)(after) == 42 | ||
* scala> import cats._, data._ | ||
* scala> val f = Cokleisli((xs: NonEmptyList[Int]) => xs.reverse.head) | ||
* f: cats.data.Cokleisli[cats.data.NonEmptyList,Int,Int] = Cokleisli(<function1>) |
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'd omit these toString renderings, just like you omitted the output of the defs. The other examples in Cats tend to omit the trivial outputs and focus on the setup and the res0.
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.
@rossabaker gotcha :)
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.
👍
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.
One minor comment. I hope you’ll indulge me but if you don’t have time we can merge and deal with it later.
* {{{ | ||
* scala> import cats._, data._ | ||
* scala> val f = Cokleisli((xs: NonEmptyList[Int]) => xs.reverse.head) | ||
* scala> def before(x: String) = x.toInt |
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 hate to be a jerk, but can we use a function that won’t throw. I know this example is safe but using toInt in general is dangerous and I hate to set the example in docs.
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.
Agree
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.
Thanks!
Thought it might be helpful to include examples on
dimap
,lmap
andrmap
for learners of the library