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 more doctest to Monad and FlatMap #4427

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

diogocanut
Copy link
Contributor

PR for part of #2479

Adding doctest for Monad and FlatMap typeclasses.

@armanbilge armanbilge changed the title Add more doctest to Monad and FlatMap Add more doctest to Monad and FlatMap Apr 17, 2023
Comment on lines 49 to 53
* scala> val appendStr: StateT[Id, String, Unit] = StateT.modify(_ + "a")
* scala> val appendStrAndGet: StateT[Id, String, String] = appendStr *> StateT.get
* scala> val (result, agg) = appendStrAndGet.whileM[Vector](StateT.inspect(i => !(i.length >= 5))).run("")
* result: String = aaaaa
* agg: Vector[String] = Vector(a, aa, aaa, aaaa, aaaaa)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of StateT[Id, ...] can't we just use State? The issue with StateT[Id, ...] is that actually it is not stacksafe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, should I use State also in all other examples that uses StateT or just this one?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. You should never use StateT[Id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I'm using State now, but there's some results that's previous result + 1, like in iterateUntilM. Is that okay?

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.

3 participants