Share your code. Components are building blocks, you are the architect.

utils/group-with
v1.1.0
1.1.0
1.0.0
MIT
PUBLIC
3
1     DEPENDENCIES
Build: fail
BuildFail
Build Status: fail
Takes a list and returns a list of lists where each sublist's elements are

Please configure Bit as a scoped registry to install components with NPM.Learn more

npm config set '@bit:registry' https://node.bitsrc.io
Use utils/group-with in your project
npm i @bit/bit.ramda.utils.group-with
Copied

groupWith (fn:Function, list:Array) : List

Takes a list and returns a list of lists where each sublist’s elements are all satisfied pairwise comparison according to the provided function. Only adjacent elements are passed to the comparison function.

Example

R.groupWith(R.equals, [0, 1, 1, 2, 3, 5, 8, 13, 21])
//=> [[0], [1, 1], [2], [3], [5], [8], [13], [21]]

R.groupWith((a, b) => a + 1 === b, [0, 1, 1, 2, 3, 5, 8, 13, 21])
//=> [[0, 1], [1, 2, 3], [5], [8], [13], [21]]

R.groupWith((a, b) => a % 2 === b % 2, [0, 1, 1, 2, 3, 5, 8, 13, 21])
//=> [[0], [1, 1], [2], [3, 5], [8], [13, 21]]

R.groupWith(R.eqBy(isVowel), 'aestiou')
//=> ['ae', 'st', 'iou']

Arguments

fn: Function

Function for determining whether two given (adjacent) elements should be in the same group

list: Array

The array to group. Also accepts a string, which will be treated as a list of characters.

Returns

List

A list that contains sublists of elements, whose concatenations are equal to the original list.