<A>(self: Iterable<A>): Iterable<A>Deduplicates adjacent elements that are identical.
Example (Deduplicating adjacent elements)
import { Iterable } from "effect"
// Remove adjacent duplicate numbers
const numbers = [1, 1, 2, 2, 2, 3, 1, 1]
const deduped = Iterable.dedupeAdjacent(numbers)
console.log(Array.from(deduped)) // [1, 2, 3, 1]
// Remove adjacent duplicate characters
const letters = "aabbccaa"
const dedupedLetters = Iterable.dedupeAdjacent(letters)
console.log(Array.from(dedupedLetters)) // ["a", "b", "c", "a"]
// Works with objects using deep equality
const objects = [
{ type: "A" },
{ type: "A" },
{ type: "B" },
{ type: "B" },
{ type: "A" }
]
const dedupedObjects = Iterable.dedupeAdjacent(objects)
console.log(Array.from(dedupedObjects).map((o) => o.type)) // ["A", "B", "A"]
// Clean up streaming data
const sensorData = [100, 100, 100, 101, 101, 102, 102, 102, 100]
const cleanedData = Iterable.dedupeAdjacent(sensorData)
console.log(Array.from(cleanedData)) // [100, 101, 102, 100]filtering
Source effect/Iterable.ts:23391 lines
export const const dedupeAdjacent: <A>(
self: Iterable<A>
) => Iterable<A>
Deduplicates adjacent elements that are identical.
Example (Deduplicating adjacent elements)
import { Iterable } from "effect"
// Remove adjacent duplicate numbers
const numbers = [1, 1, 2, 2, 2, 3, 1, 1]
const deduped = Iterable.dedupeAdjacent(numbers)
console.log(Array.from(deduped)) // [1, 2, 3, 1]
// Remove adjacent duplicate characters
const letters = "aabbccaa"
const dedupedLetters = Iterable.dedupeAdjacent(letters)
console.log(Array.from(dedupedLetters)) // ["a", "b", "c", "a"]
// Works with objects using deep equality
const objects = [
{ type: "A" },
{ type: "A" },
{ type: "B" },
{ type: "B" },
{ type: "A" }
]
const dedupedObjects = Iterable.dedupeAdjacent(objects)
console.log(Array.from(dedupedObjects).map((o) => o.type)) // ["A", "B", "A"]
// Clean up streaming data
const sensorData = [100, 100, 100, 101, 101, 102, 102, 102, 100]
const cleanedData = Iterable.dedupeAdjacent(sensorData)
console.log(Array.from(cleanedData)) // [100, 101, 102, 100]
dedupeAdjacent: <function (type parameter) A in <A>(self: Iterable<A>): Iterable<A>A>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>): Iterable<A>A>) => interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>): Iterable<A>A> = const dedupeAdjacentWith: <A>(isEquivalent: (self: A, that: A) => boolean) => (self: Iterable<A>) => Iterable<A> (+1 overload)dedupeAdjacentWith(import EqualEqual.asEquivalence())