import type { Eq } from "@principia/prelude/Eq"; import { elem_ } from "./guards"; /* * ------------------------------------------- * Set Constructors * ------------------------------------------- */ export const fromSet = (s: Set): ReadonlySet => new Set(s); export const empty: ReadonlySet = new Set(); export const singleton = (a: A): ReadonlySet => new Set([a]); export const fromArray_ = (as: ReadonlyArray, E: Eq): ReadonlySet => { const len = as.length; const r = new Set(); const has = elem_(E); for (let i = 0; i < len; i++) { const a = as[i]; if (!has(r, a)) { r.add(a); } } return r; }; export const fromArray = (E: Eq) => (as: ReadonlyArray): ReadonlySet => fromArray_(as, E);