diff --git a/packages/associative/src/merge-apply.ts b/packages/associative/src/merge-apply.ts index 044d92b0e5..8d70f70012 100644 --- a/packages/associative/src/merge-apply.ts +++ b/packages/associative/src/merge-apply.ts @@ -1,7 +1,7 @@ import type { Fn, IObjectOf } from "@thi.ng/api"; import { isFunction } from "@thi.ng/checks/is-function"; import { isIllegalKey } from "@thi.ng/checks/is-proto-path"; -import { copy } from "./utils"; +import { copy, copyObj } from "./utils"; /** * Similar to {@link mergeApplyObj}, but for ES6 Maps instead of plain objects. @@ -51,7 +51,7 @@ export const mergeApplyMap = ( export const mergeApplyObj = ( src: IObjectOf, xs: IObjectOf> -) => meldApplyObj({ ...src }, xs); +) => meldApplyObj(copyObj(src), xs); /** * Mutable version of {@link mergeApplyObj}. Returns modified `src` diff --git a/packages/associative/src/merge-with.ts b/packages/associative/src/merge-with.ts index 3cfc7b9fe7..3304a63148 100644 --- a/packages/associative/src/merge-with.ts +++ b/packages/associative/src/merge-with.ts @@ -1,6 +1,6 @@ import type { Fn2, IObjectOf, Nullable } from "@thi.ng/api"; import { isIllegalKey } from "@thi.ng/checks/is-proto-path"; -import { copy } from "./utils"; +import { copy, copyObj } from "./utils"; export const mergeMapWith = ( f: Fn2, @@ -35,7 +35,7 @@ export const mergeObjWith = ( f: Fn2, dest: IObjectOf, ...xs: Nullable>[] -) => meldObjWith(f, { ...dest }, ...xs); +) => meldObjWith(f, copyObj(dest), ...xs); /** * Mutable version of {@link mergeObjWith}. Returns modified `dest` diff --git a/packages/associative/src/sparse-set.ts b/packages/associative/src/sparse-set.ts index 33035006eb..dd8a574258 100644 --- a/packages/associative/src/sparse-set.ts +++ b/packages/associative/src/sparse-set.ts @@ -42,7 +42,7 @@ export abstract class ASparseSet return __private.get(this)!.n; } - get capacity() { + get capacity(): number { return __private.get(this)!.dense.length; } diff --git a/packages/associative/src/utils.ts b/packages/associative/src/utils.ts index e45a5be1da..273119838b 100644 --- a/packages/associative/src/utils.ts +++ b/packages/associative/src/utils.ts @@ -1,6 +1,7 @@ import type { Pair } from "@thi.ng/api"; import { implementsFunction } from "@thi.ng/checks/implements-function"; import { isMap } from "@thi.ng/checks/is-map"; +import { isIllegalKey } from "@thi.ng/checks/is-proto-path"; import { isSet } from "@thi.ng/checks/is-set"; export const empty = (x: any, ctor: Function) => @@ -13,6 +14,14 @@ export const copy = (x: any, ctor: Function) => ? x.copy() : new (x[Symbol.species] || ctor)(x); +export const copyObj = (x: any) => { + const res: any = {}; + for (let k in x) { + !isIllegalKey(k) && (res[k] = x[k]); + } + return res; +}; + export const first = (x: Iterable) => x[Symbol.iterator]().next().value; export const objValues = (src: any) => {