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 some FlatMap loops useful for State and Effects #2249

Merged
merged 4 commits into from
May 8, 2018

Conversation

johnynek
Copy link
Contributor

@johnynek johnynek commented May 6, 2018

Three cases I have wanted:

  1. taking a scalacheck Gen[Option[A]] => Gen[A]
  2. writing a server that has a single step as IO[Unit] then repeating that forever.
  3. a server that has some state: S => IO[S] that each call updates the state and repeat forever.

This has to be done with syntax backwards compatibility hacks, but we can repair that at cats 2.0

* for polling type operations on State (or RNG) Monads, or in effect
* monads.
*/
def untilDefined(implicit F: FlatMap[F]): F[A] =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't name this the same as untilDefinedM because it is slightly different. OptionT[F, Option[A]] should still have access to untilDefinedM. This can possibly be removed since it adds little over optt.value.untilDefinedM

@codecov-io
Copy link

codecov-io commented May 6, 2018

Codecov Report

Merging #2249 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2249      +/-   ##
==========================================
+ Coverage   94.95%   94.96%   +<.01%     
==========================================
  Files         333      333              
  Lines        5788     5797       +9     
  Branches      221      221              
==========================================
+ Hits         5496     5505       +9     
  Misses        292      292
Impacted Files Coverage Δ
testkit/src/main/scala/cats/tests/CatsSuite.scala 70% <ø> (ø) ⬆️
core/src/main/scala/cats/syntax/flatMap.scala 80.95% <100%> (+14.28%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 069caf2...4da23e1. Read the comment docs.

LukaJCB
LukaJCB previously approved these changes May 7, 2018
Copy link
Member

@LukaJCB LukaJCB left a comment

Choose a reason for hiding this comment

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

Seems pretty useful to me 👍

case Left(big) => big should === (1001)
case Right((_, _)) => fail("unreachable code due to Nothing, but scalac won't let us match on it")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick. The current implementation looks stack safe, but shall we still add a stack safety test for future guard rail?

@johnynek
Copy link
Contributor Author

johnynek commented May 8, 2018

@kailuowang look good now?

@kailuowang
Copy link
Contributor

Thanks for adding the test. @johnynek

@johnynek johnynek merged commit 680a517 into master May 8, 2018
@johnynek johnynek deleted the oscar/add_some_monadic_loops branch May 8, 2018 18:36
@stew stew removed the in progress label May 8, 2018
@kailuowang kailuowang added this to the 1.2 milestone May 30, 2018
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.

5 participants