import type { Eq } from "@principia/prelude/Eq"; import * as O from "../Option"; import { lookupWithKey } from "./combinators"; interface Next { readonly done?: boolean; readonly value: A; } /** * Test whether or not a map is empty */ export const isEmpty = (d: ReadonlyMap): boolean => d.size === 0; /** * Test whether or not one `Map` contains all of the keys and values contained in another `Map` * * @since 1.0.0 */ export const isSubmap_ = (EK: Eq, EA: Eq) => { const lookupWithKeyE = lookupWithKey(EK); return (me: ReadonlyMap, that: ReadonlyMap) => { const entries = me.entries(); let e: Next; while (!(e = entries.next()).done) { const [k, a] = e.value; const d2OptA = lookupWithKeyE(k)(that); if (O.isNone(d2OptA) || !EK.equals_(k, d2OptA.value[0]) || !EA.equals_(a, d2OptA.value[1])) { return false; } } return true; }; }; export const isSubmap = (EK: Eq, EA: Eq) => { const isSubmapKA_ = isSubmap_(EK, EA); return (that: ReadonlyMap) => (me: ReadonlyMap) => isSubmapKA_(me, that); };