0

Is there a way to map a tuple?

Tried the following but not working

(a, b).map(v1,v2 => SomeFunction(v1, v2)

Possible alternative is case class

      (a, b) match {
          case (Some(v1), Some(v2)) => SomeFunction(a, b)
          case _ => None
        }

Wondering if there's other alternative.

Nithin Chandy
  • 686
  • 1
  • 10
  • 28

1 Answers1

1

You can iterate over tuples and then map() over the Iterator ...

(9,'c',true).productIterator.map(???)

... but tuples hold elements of differing types so the iterator is Iterator[Any] which isn't likely to be useful or safe.

jwvh
  • 50,871
  • 7
  • 38
  • 64