-
-
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 more doctest to Monad
and FlatMap
#4427
base: main
Are you sure you want to change the base?
Conversation
Monad
and FlatMap
core/src/main/scala/cats/Monad.scala
Outdated
* 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) |
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.
Instead of StateT[Id, ...]
can't we just use State
? The issue with StateT[Id, ...]
is that actually it is not stacksafe.
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, should I use State
also in all other examples that uses StateT
or just this one?
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.
Yes. You should never use StateT[Id
.
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.
Done. I'm using State
now, but there's some results that's previous result + 1, like in iterateUntilM
. Is that okay?
PR for part of #2479
Adding doctest for
Monad
andFlatMap
typeclasses.