group-with

v0.9.6arrow_drop_down
v0.9.6
STATUS
Passing
DOWNLOADS
2
VISIBILITY
Public
PUBLISHED
5 years ago
SIZE
859 B
Takes a list and returns a list of lists where each sublist's elements are all satisfied pairwise comparison according to the provided function.
1 contributor
Install group-with as a package?
Copied
npm i @bit/justin-capalbo.ramda.group-with
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
No preview available
modifieddraft
chevron_left
chevron_right
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.

Help and resources