Skip to content

Instantly share code, notes, and snippets.

@qingwei91
Created December 20, 2019 14:27
Show Gist options
  • Select an option

  • Save qingwei91/37d2c4e32abc383bb6cf97e41f8c7dc7 to your computer and use it in GitHub Desktop.

Select an option

Save qingwei91/37d2c4e32abc383bb6cf97e41f8c7dc7 to your computer and use it in GitHub Desktop.
Use IO to wrap each loop
import cats.effect._
def retryIfNone(innerIO: IO[Option[Int]]): IO[Int] = {
innerIO.flatMap {
case Some(i) =>
println("something") // used to show some output when testing
IO.pure(i)
case None =>
println("nothing") // used to show some output when testing
retryIfNone(innerIO)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment