<A>(self: Iterable<A>): Iterable<NonEmptyArray<A>>Groups equal, consecutive elements of an Iterable into NonEmptyArrays.
Example (Grouping consecutive elements)
import { Iterable } from "effect"
const numbers = [1, 1, 2, 2, 2, 3, 1, 1]
const grouped = Iterable.group(numbers)
console.log(Array.from(grouped))
// [[1, 1], [2, 2, 2], [3], [1, 1]]
const letters = "aabbccaa"
const groupedLetters = Iterable.group(letters)
console.log(Array.from(groupedLetters))
// [["a", "a"], ["b", "b"], ["c", "c"], ["a", "a"]]
// Works with objects using deep equality
const objects = [
{ type: "A", value: 1 },
{ type: "A", value: 1 },
{ type: "B", value: 2 },
{ type: "A", value: 1 }
]
const groupedObjects = Iterable.group(objects)
console.log(Array.from(groupedObjects).length) // 3 groups
// Note: Only consecutive equal objects are grouped togethergrouping
Source effect/Iterable.ts:12973 lines
export const const group: <A>(
self: Iterable<A>
) => Iterable<NonEmptyArray<A>>
Groups equal, consecutive elements of an Iterable into NonEmptyArrays.
Example (Grouping consecutive elements)
import { Iterable } from "effect"
const numbers = [1, 1, 2, 2, 2, 3, 1, 1]
const grouped = Iterable.group(numbers)
console.log(Array.from(grouped))
// [[1, 1], [2, 2, 2], [3], [1, 1]]
const letters = "aabbccaa"
const groupedLetters = Iterable.group(letters)
console.log(Array.from(groupedLetters))
// [["a", "a"], ["b", "b"], ["c", "c"], ["a", "a"]]
// Works with objects using deep equality
const objects = [
{ type: "A", value: 1 },
{ type: "A", value: 1 },
{ type: "B", value: 2 },
{ type: "A", value: 1 }
]
const groupedObjects = Iterable.group(objects)
console.log(Array.from(groupedObjects).length) // 3 groups
// Note: Only consecutive equal objects are grouped together
group: <function (type parameter) A in <A>(self: Iterable<A>): Iterable<NonEmptyArray<A>>A>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>): Iterable<NonEmptyArray<A>>A>) => interface Iterable<T, TReturn = any, TNext = any>Iterable<import NonEmptyArrayNonEmptyArray<function (type parameter) A in <A>(self: Iterable<A>): Iterable<NonEmptyArray<A>>A>> = const groupWith: {
<A>(
isEquivalent: (self: A, that: A) => boolean
): (
self: Iterable<A>
) => Iterable<NonEmptyArray<A>>
<A>(
self: Iterable<A>,
isEquivalent: (self: A, that: A) => boolean
): Iterable<NonEmptyArray<A>>
}
groupWith(
import EqualEqual.asEquivalence()
)