for-comprehension yield raises type mismatch compiler error
问题 I want to extract from Iterable[Try[Int]] a list of all valid values ( Iterable[Int] ) val test = List( Try(8), Try(throw new RuntimeException("foo")), Try(42), Try(throw new RuntimeException("bar")) ) The following is the way to print all valid values from test : for { n <- test p <- n } println(p) // Output // 8 // 42 However, when I tried to save the valid values to list I have received an error: val nums: Seq[Int] = for { n <- list p <- n // Type mismatch. Required: IterableOnce[Int],