简体   繁体   中英

Scala zip arbitrary number of arrays together

I'm trying to zip array of arbitrary length in Scala into a single array.

val someArray = Array(Array(1,2,3), Array(4,5,6), Array(7,8,9))

 // expected result
Array(Array(1,4,7), Array(2,5,8), Array(3,6,9))

The outer array length may vary, whereas the inner array length will be the same. the end ouput can be in any form arrays, lists or tuples Is there any scala function to achieve this? or how would you get this output? Any help is appreciated.

Shortest answer I ever wrote on StackOverflow:

someArray.transpose

Link to docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM