Core concept
def get(k: String): Option[Int] = Some(1)
val sum = get("a").flatMap(a => get("b").map(b => a + b))Advertisement
How it works
Deep nesting readability suffers. For-comprehension often cleaner.
Advertisement
Trade-offs + gotchas
Any monadic composition. Option, Either, Future, IO.