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 doctest for IdT
#4445
Add doctest for IdT
#4445
Conversation
* scala> import cats.~> | ||
* scala> import cats.data.IdT | ||
* | ||
* scala> val vectorToList: Vector ~> List = new ~>[Vector, List] { override def apply[A](v: Vector[A]): List[A] = v.toList } |
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.
This part can be simplified :
* scala> val vectorToList: Vector ~> List = new ~>[Vector, List] { override def apply[A](v: Vector[A]): List[A] = v.toList } | |
* scala> val vectorToList: Vector ~> List = FunctionK.liftFunction(_.toList) |
(requires import cats.arrow.FunctionK
)
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.
(for Scala3 the syntax is going to be slightly different though)
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.
Sure, it could have written it that way, I just wrote it in detail so that anybody could fully see how it happens)
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.
Well, I'm leaning to think that examples in scaladocs should keep the examples as simple as possible. Whereas the details on how, let's say, FunctionK
works is supposed to be captured in the FunctionK
scaladocs per se.
But I don't think it's really worth bikeshedding anyway – in any case it is a great job on providing the missing docs for the class, thank you for doing this!
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'm not sure if we can write it like that, don't the doctests have to cross-compile for Scala 2 and Scala 3? So we are stuck with worst-of-both-worlds syntax.
Thank you for the PR! Looks good to me in general, the only nit is regarding mapK: I think it would make sense to show a simplified FunctionK syntax in the examples. |
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.
Just a couple nits, but overall this looks great and I think we should get it into the next release. Thanks for all your work, and sorry for the slow review cycle!
* scala> import cats.data.IdT | ||
* | ||
* scala> val idT: IdT[List, Int] = IdT(List(1, 2, 3)) | ||
* scala> idT.flatMap(x => IdT(List(x + 1))) |
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.
A more interesting demo of flatMap
might do something like this. Otherwise it's a glorified map
😉
* scala> idT.flatMap(x => IdT(List(x + 1))) | |
* scala> idT.flatMap(x => IdT(List(x + 1, x + 2))) |
* scala> import cats.data.IdT | ||
* | ||
* scala> val idT: IdT[List, Int] = IdT(List(1, 2, 3)) | ||
* scala> idT.flatMapF(x => List(Option(x).filter(_ % 2 == 0))) |
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.
Same with this one, it's basically just demoing a map. Actually, I'd do the example without the Option
, it's a bit distracting IMO.
PR for part of #2479
Adding doctest for IdT typeclass.