Skip to content

Instantly share code, notes, and snippets.

@neftaly
Created May 3, 2017 09:37
Show Gist options
  • Save neftaly/8178b792d02fb6d2acd9ebae5a288908 to your computer and use it in GitHub Desktop.
Save neftaly/8178b792d02fb6d2acd9ebae5a288908 to your computer and use it in GitHub Desktop.
// Split an array every time the predicate returns true
// :: f => (array -> Boolean) -> f a -> f a
const segment = R.curry((fn, array) => {
const chunks = [];
let chunk = [];
for (let value of array) {
if (fn(value)) {
chunks.push(chunk);
chunk = [];
}
chunk.push(value);
}
chunks.push(chunk);
return chunks;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment