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 doctest for IdT #4445

Merged
merged 1 commit into from Jul 10, 2023
Merged

Add doctest for IdT #4445

merged 1 commit into from Jul 10, 2023

Conversation

bulatkhabib
Copy link

PR for part of #2479

Adding doctest for IdT typeclass.

* 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 }
Copy link
Contributor

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 :

Suggested change
* 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)

Copy link
Contributor

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)

Copy link
Author

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)

Copy link
Contributor

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!

Copy link
Member

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.

@satorg
Copy link
Contributor

satorg commented Jun 12, 2023

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.

Copy link
Member

@armanbilge armanbilge left a 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)))
Copy link
Member

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 😉

Suggested change
* 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)))
Copy link
Member

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.

@armanbilge armanbilge changed the title Add doctest for IdT Add doctest for IdT Jun 26, 2023
@johnynek johnynek merged commit bdb06c9 into typelevel:main Jul 10, 2023
15 checks passed
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.

None yet

4 participants