Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created July 24, 2012 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Raynos/3171982 to your computer and use it in GitHub Desktop.
Save Raynos/3171982 to your computer and use it in GitHub Desktop.
Creating n sized lists
// curry is ncurry(2)
var intoList = curry(function (size, list, elem) {
var lastElem = last(list)
if (lastElem && lastElem.length < size) {
lastElem.push(elem)
} else {
list.push([elem])
}
return list
})
, intoTriplet = intoList(3)
, intoTuple = intoList(2)
// reduce is Array.prototype.reduce.call.bind(Array.prototype.reduce)
reduce(list, intoTriplet, [])
reduce(list, intoTuple, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment