After reading this question, I would expect the following to work:
Seq( Seq(1,2,3) , Seq(4,5,6) ).transpose()
but alas:
error: not enough arguments for method transpose: (implicit asTraversable:
Seq[Int] => scala.collection.GenTraversableOnce[B])Seq[Seq[B]].
Unspecified value parameter asTraversable.
Seq( Seq(1,2,3) , Seq(4,5,6) ).transpose()
Also, I can’t seem to find any reference to transpose on the scala docs, although Seq refers it
Providing the identity, it seems to work somehow:
scala> Seq( Seq(1,2,3) , Seq(4,5,6) ).transpose( a => a)
res10: Seq[Seq[Int]] = List(List(1, 4), List(2, 5), List(3, 6))
But still returns List instead of Seq
Just use it without parentheses:
But still returns List instead of Seq
Well, actually List is inheritor of Seq, so after all you got a Seq (look at the left part of result).
The reason of such behaviour is that transpose actually defined as a function with argument, but since it’s argument defined as implicit you have an option to delegate work of substituting argument to scala compiler (it will perform compile-time lookup for you).
If you writing parentheses, either function has to have overloaded form with no arguments, e.g.
or you have to write something inside them (it’s actually matter of syntax).