Tuple methods #12888
-
Hi! But one thing that feels weird is there are no corresponding methods with said types. No method So what are the plans for those methods? Should they be implemented at all? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
One way to implement it is like this where we perform the operations on arrays. import Tuple.FlatMap
extension (tup: Tuple)
def flatMap[F[_] <: Tuple](f: [t] => t => F[t]): FlatMap[tup.type, F] =
flatMapOnUnderlyingArrays(tup, f).asInstanceOf[FlatMap[tup.type, F]]
private def flatMapOnUnderlyingArrays[F[_] <: Tuple](self: Tuple, f: [t] => t => F[t]): Tuple = self match {
case EmptyTuple => self
case _ => Tuple.fromIArray(IArray.from(self.productIterator.flatMap(f(_).productIterator)))
}
def tests =
val tup1: (Int, Int, String, String, Double, Double) = (1, "a", 3.0).flatMap[[t] =>> (t, t)]([t] => (x: t) => (x, x))
() |
Beta Was this translation helpful? Give feedback.
One way to implement it is like this where we perform the operations on arrays.