Skip to content

Commit

Permalink
feat(pointfree): add copy() word
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Apr 1, 2018
1 parent 42cc778 commit 68a8dba
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/pointfree/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { illegalState, illegalArgs } from "@thi.ng/api/error";
import { equiv as _equiv } from "@thi.ng/api/equiv";
import { isArray } from "@thi.ng/checks/is-array";
import { isFunction } from "@thi.ng/checks/is-function";
import { isPlainObject } from "@thi.ng/checks/is-plain-object";

import { StackContext, StackProc, StackEnv, StackProgram, StackFn, Stack } from "./api";
import { comp } from "./comp";
Expand Down Expand Up @@ -1539,6 +1540,17 @@ export const join = (sep = "") => op1((x) => x.join(sep));
*/
export const length = op1((x) => x.length);

/**
* Replaces TOS with its shallow copy. MUST be an array or plain object.
*
* ( x -- copy )
*/
export const copy = op1((x) =>
isArray(x) ?
[...x] :
isPlainObject(x) ? { ...x } :
illegalArgs(`can't copy type ${typeof x}`));

/**
* Reads key/index from object/array.
*
Expand Down

0 comments on commit 68a8dba

Please sign in to comment.