Given the function, f
, which, given a 2-tuple of Option[A]
's, puts non-empty tuple elements into an output List[A]
:
def f[A](xs: (Option[A], Option[A])): List[A] = xs match {
case (Some(x), Some(y)) => List(x, y)
case (None, Some(y)) => List(y)
case (Some(x), None) => List(x)
case (None, None) => List.empty
}
How can I write a generic f
, i.e. fGen
, that will handle any tuple size, i.e. 2 to N?
Perhaps I can use shapeless?