Skip to content

Instantly share code, notes, and snippets.

@sortega
Created June 25, 2017 17:04
Show Gist options
  • Save sortega/e360f1e49a570728d0df5005e1a71f75 to your computer and use it in GitHub Desktop.
Save sortega/e360f1e49a570728d0df5005e1a71f75 to your computer and use it in GitHub Desktop.
Some snippet for an explanation
package futures
import scala.concurrent.Future
object Snippet {
type A = String
type B = Int
def first(x: String): Future[Option[A]] = ???
def second(a: A): Future[List[B]] = ???
def fallback: Future[List[B]] = ???
val justFlatMap: Future[List[B]] = first("arg").flatMap(_.fold(fallback)(second))
val comprehension: Future[List[B]] = for {
maybeA <- first("arg")
results <- maybeA.fold(fallback)(second)
} yield results
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment