Created
October 17, 2014 18:07
-
-
Save davidchambers/c952e2e27d12058b618b to your computer and use it in GitHub Desktop.
zipMany implementation with Ramda, created with @benperez
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ] ] |
ivan-kleshnin
commented
Sep 6, 2017
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