You can use flatMap when returning Options , because the implicit conversion from Option to Iterable an implicit option2Iterable . The flatMap method on your List[(Int, Int)] expects a function from (Int, Int) to GenTraversableOnce[Int] . The compiler has trouble determining that implicit conversion is a viable option here. You can help the compiler by explicitly specifying your general parameters:
import Function._ data.flatMap[String, Iterable[String]](tupled(f)) //Or data flatMap tupled[Int, Int, Iterable[String]](f)
Other formulations of the same idea may also allow the compiler to select the correct types and implicits, even without explicit generics:
data flatMap (tupled(f _)(_)) data.flatMap (f.tupled(f _)(_))
Finally, you can also play with collect along with unlift here, which can be a good way to express this logic:
data collect unlift((f _).tupled) data collect unlift(tupled(f))
Function.unlift accepts a method that returns Option and turns it into a PartialFunction , which does not match the return of the original None function. collect accepts a partial function and collects the values ββof the partial function, if defined for each element.
source share