import * as Chunk from "effect/Chunk" import type * as Equivalence from "effect/Equivalence" export function toArray( gen: Generator ) { return Array.from(gen) } /** * Remove duplicates from an array, keeping the first occurrence of an element. */ export function uniq(E: Equivalence.Equivalence) { return (self: Chunk.Chunk): Chunk.Chunk => { let out = Chunk.fromIterable([]) for (let i = 0; i < self.length; i++) { const a = Chunk.getUnsafe(self, i) if (!elem(E, a)(out)) { out = Chunk.append(out, a) } } return self.length === out.length ? self : out } } /** * Test if a value is a member of an array. Takes a `Equivalence.Equivalence` as a single * argument which returns the function to use to search for a value of type `A` * in an array of type `Chunk.Chunk`. */ export function elem(E: Equivalence.Equivalence, value: A) { return (self: Chunk.Chunk): boolean => { for (let i = 0; i < self.length; i++) { if (E(Chunk.getUnsafe(self, i), value)) { return true } } return false } }