3 つの IndexedSequences があり、次のように組み合わせることができます。
indSeq1 = (a,b,c)
indSeq2 = (1,2,3)
indSeq3 = (!,@,#)
result:([a,1,!],[b,2,@],[c,3,#])
私はzip([a,b,c],[1,2,3],[!,@,#])
形式を使用しましたが、Scalaでこれを行うにはどうすればよいですか。出力をIndexedSequenceにもしたいです。
これは、私がそれを行うときに得られるものではありません:
scala> val indSeq1 = Seq('a', 'b', 'c')
indSeq1: Seq[Char] = List(a, b, c)
scala> val indSeq2 = Seq(1,2,3)
indSeq2: Seq[Int] = List(1, 2, 3)
scala> val indSeq3 = Seq('!', '@', '#')
indSeq3: Seq[Char] = List(!, @, #)
scala> (indSeq1, indSeq2, indSeq3).zipped
res30: scala.runtime.Tuple3Zipped[Char,Seq[Char],Int,Seq[Int],Char,Seq[Char]] = scala.runtime.Tuple3Zipped@9789aa5f
scala> res30.toSeq
res31: Seq[(Char, Int, Char)] = Stream((a,1,!), ?)
scala> res30.toList
res32: List[(Char, Int, Char)] = List((a,1,!), (b,2,@), (c,3,#))
scala> res30.toIndexedSeq
res33: scala.collection.immutable.IndexedSeq[(Char, Int, Char)] = Vector((a,1,!), (b,2,@), (c,3,#))
次のようinvert
に onメソッドを使用するだけです。Tuple3
scala> val s1 = IndexedSeq('a', 'b', 'c')
s1: IndexedSeq[Char] = Vector(a, b, c)
scala> val s2 = Seq(1, 2, 3)
s2: Seq[Int] = List(1, 2, 3)
scala> val s3 = Seq('!, '@, '#)
s3: Seq[Symbol] = List('!, '@, '#)
scala> (s1, s2, s3).invert
res0: IndexedSeq[(Char, Int, Symbol)] = Vector((a,1,'!), (b,2,'@), (c,3,'#))
圧縮後に転置を実行してみてください。