import type { Lazy } from "../Function"; import type { LazyList } from "./model"; /* * ------------------------------------------- * Constructors * ------------------------------------------- */ export const nil: LazyList = { _tag: "Nil" }; export const cons_ = (head: Lazy, tail: Lazy>): LazyList => ({ _tag: "Cons", head, tail }); export const cons = (head: Lazy) => (tail: Lazy>): LazyList => cons_(head, tail); export const list = (...xs: ReadonlyArray): LazyList => xs.length === 0 ? nil : cons_( () => xs[0], () => list(...xs.slice(1)) ); export const fromArray = (xs: ReadonlyArray): LazyList => list(...xs);