Top "For-comprehension" questions

for-comprehension is construction in Scala language allowing easy iteration over one or more collections.

Confused with the for-comprehension to flatMap/Map transformation

I really don't seem to be understanding Map and FlatMap. What I am failing to understand is how a for-comprehension …

scala map monads for-comprehension
How can I do 'if..else' inside a for-comprehension?

I am asking a very basic question which confused me recently. I want to write a Scala For expression to …

scala for-comprehension
Future[Option] in Scala for-comprehensions

I have two functions which return Futures. I'm trying to feed a modified result from first function into the other …

scala future for-comprehension
Composing Option with List in for-comprehension gives type mismatch depending on order

Why does this construction cause a Type Mismatch error in Scala? for (first <- Some(1); second <- List(1,2,3)) …

scala for-loop type-mismatch for-comprehension scala-option
withFilter instead of filter

Is it always more performant to use withFilter instead of filter, when afterwards applying functions like map, flatmap etc.? Why …

scala lazy-evaluation scala-collections for-comprehension
Scala Future with filter in for comprehension

In the example below I get the exception java.util.NoSuchElementException: Future.filter predicate is not satisfied I want to …

scala filter future for-comprehension
Scala "<-" for comprehension

I have found that Scala always has a "natural explanation" to anything. Always something like "ohh, but that's just a …

scala loops compiler-theory for-comprehension
Using Eithers with Scala "for" syntax

As I understand it, Scala "for" syntax is extremely similar to Haskell's monadic "do" syntax. In Scala, "for" syntax is …

scala monads typeclass for-comprehension either
Cartesian product of two lists

Given a map where a digit is associated to several characters scala> val conversion = Map("0" -> List("A", "…

scala for-comprehension
println in scala for-comprehension

In a for-comprehension, I can't just put a print statement: def prod (m: Int) = { for (a <- 2 to m/(2*3); …

scala variable-assignment println for-comprehension