Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

what is the best idiom to perform the opposite of "zip"? (besides "unfold")

28 views
Skip to first unread message

bwv549

unread,
Oct 2, 2012, 12:37:46 AM10/2/12
to
I need to turn some list of pairs into two arrays (the opposite of zipping two arrays together). There is a solution using "unfold" here (http://weblog.raganwald.com/2007/11/really-useful-anamorphisms-in-ruby.html) but that seems like more than what I want for this task.

I want to turn this:
[[1,2][3,4],[5,6]]

Into:
[[1,3,5], [2,4,6]]

What's the best ruby idiom for doing this task. Can it be generalized for triplets, quadruplets, etc.?

Or, if you use unfold, is there a particular gem you use and does it take a major performance hit?

bwv549

unread,
Oct 2, 2012, 12:42:42 AM10/2/12
to
Array#transpose

And I've used and recommended this many times...
0 new messages