Created
June 25, 2017 17:04
-
-
Save sortega/e360f1e49a570728d0df5005e1a71f75 to your computer and use it in GitHub Desktop.
Some snippet for an explanation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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