Created
June 13, 2017 14:03
-
-
Save theikkila/773932473cdc5d4e0ab6866700460a8b to your computer and use it in GitHub Desktop.
Ramda receipts
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
const partitionBy = (f, collection) => { | |
const r = collection.reduce(({result, currentPartition, partitions}, item) => { | |
const newResult = f(item) | |
if (result != undefined && result != newResult) { | |
return {result: newResult, currentPartition: [item], partitions: R.append(currentPartition, partitions)} | |
} | |
return {result: newResult, currentPartition: R.append(item, currentPartition), partitions} | |
}, {result: undefined, currentPartition:[], partitions: []}) | |
return R.append(r.currentPartition, r.partitions) | |
} | |
// partitionBy works like Clojures partition-by |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment