export function intersperse(as: A[], separator: (index: number) => A): A[] { return as.flatMap((a, i) => (i ? [separator(i), a] : [a])) } export function count(arr: readonly T[], pred: (x: T) => unknown): number { let n = 0 for (const x of arr) n += +!!pred(x) return n } export function uniq(xs: Iterable): T[] { return [...new Set(xs)] }