MCPcopy Create free account
hub / github.com/Effect-TS/effect / dedupe

Function dedupe

packages/effect/src/Array.ts:4689–4704  ·  view source on GitHub ↗
(
  self: S
)

Source from the content-addressed store, hash-verified

4687 * @since 2.0.0
4688 */
4689export const dedupe = <S extends Iterable<any>>(
4690 self: S
4691): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never => {
4692 const input = fromIterable(self)
4693 if (input.length < 2) {
4694 return [...input] as any
4695 }
4696 const buckets: HashBuckets = new Map()
4697 const out: Array<unknown> = []
4698 for (const value of input) {
4699 if (hashBucketsAdd(buckets, value)) {
4700 out.push(value)
4701 }
4702 }
4703 return out as any
4704}
4705
4706/**
4707 * Removes consecutive duplicate elements using a custom equivalence.

Callers 2

Array.tsFile · 0.70
Array.test.tsFile · 0.50

Calls 3

hashBucketsAddFunction · 0.85
fromIterableFunction · 0.70
pushMethod · 0.65

Tested by

no test coverage detected