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

Function dedupe

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

Source from the content-addressed store, hash-verified

4497 * @since 2.0.0
4498 */
4499export const dedupe = <S extends Iterable<any>>(
4500 self: S
4501): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never => {
4502 const input = fromIterable(self)
4503 if (input.length < 2) {
4504 return [...input] as any
4505 }
4506 const buckets: HashBuckets = new Map()
4507 const out: Array<unknown> = []
4508 for (const value of input) {
4509 if (hashBucketsAdd(buckets, value)) {
4510 out.push(value)
4511 }
4512 }
4513 return out as any
4514}
4515
4516/**
4517 * Removes consecutive duplicate elements using a custom equivalence.

Callers 2

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

Calls 3

hashBucketsAddFunction · 0.85
pushMethod · 0.80
fromIterableFunction · 0.70

Tested by

no test coverage detected