스칼라

// For-comprehensions // Since lifting functions is so common in Scala, Scala provides a syntactic construct // called the for-comprehension that it expands automatically to a series of flatMap and // map calls. Let’s look at how map2 could be implemented with for-comprehensions. // Here’s our original version: def map2[A,B,C](a: Option[A], b: Option[B])(f: (A, B) => C): Option[C] = a.flatMap(aa => b.map(bb => f(aa, bb) ) ) // And here’s the exact same code written as a for-comprehension: def map2[A,B,C](a: Option[A], b: Option[B])(f: (A, B) => C): Option[C] = for { aa <- a bb <- b } yield f(aa, bb) // A for-comprehension consists of a sequence of bindings, like aa <- a, followed by a // yield after the closing brace, where the yield may make use of any of the values // on the left side of any previous <- binding. The compiler desugars the bindings to // flatMap calls, with the final binding and yield being converted to a call to map. // You should feel free to use for-comprehensions in place of explicit calls to flatMap // and map.


코틀린은 위에 표현밖에 지원 안 함

스칼라는 밑에 것도 지원하고