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

For comprehensions are converted into calls to the map or flatMap method. For example this one: for(x <- List(1) ; y <- List(1,2,3)) yield (x,y) becomes that: List(1).flatMap(x => List(1,2,3).map(y => (x,y))) Therefore, the first loop value (in this case, List(1)) will receive the flatMap method call. Since flatMap on a List returns another List, … Read more