Skip to content

Instantly share code, notes, and snippets.

@davidchambers
Created October 17, 2014 18:07
Show Gist options
  • Save davidchambers/c952e2e27d12058b618b to your computer and use it in GitHub Desktop.
Save davidchambers/c952e2e27d12058b618b to your computer and use it in GitHub Desktop.
zipMany implementation with Ramda, created with @benperez
var R = require('ramda');
var zipMany =
R.cond(R.isEmpty,
R.always([]),
R.converge(R.map,
R.flip(R.pluck),
R.pipe(R.head, R.length, R.range(0))));
var zipMany2 = function(lists) {
return R.isEmpty(lists) ? [] :
R.map(R.rPartial(R.pluck, lists), R.range(0, R.length(R.head(lists))));
};
zipMany([['foo', 'bar', 'baz'], [1, 2, 3], ['a', 'b', 'c']]);
// => [ [ 'foo', 1, 'a' ], [ 'bar', 2, 'b' ], [ 'baz', 3, 'c' ] ]
@henriquekano
Copy link

Kinda of an old thread, but if someone end up here:
https://ramdajs.com/docs/#transpose

// from 0.27 docs: 
R.transpose([[1, 'a'], [2, 'b'], [3, 'c']]) //=> [[1, 2, 3], ['a', 'b', 'c']]
R.transpose([[1, 2, 3], ['a', 'b', 'c']]) //=> [[1, 'a'], [2, 'b'], [3, 'c']]

:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment