0

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にもしたいです。

4

3 に答える 3

2

これは、私がそれを行うときに得られるものではありませ:

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,#))
于 2013-02-24T05:54:03.143 に答える
2

次のよう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,'#))
于 2013-02-24T10:15:55.870 に答える
0

圧縮後に転置を実行してみてください。

于 2013-02-24T05:16:26.827 に答える