@mojir/lits 2.2.4 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/cli/cli.js +1264 -909
- package/dist/cli/src/Lits/Lits.d.ts +8 -2
- package/dist/cli/src/builtin/bindingNode.d.ts +2 -1
- package/dist/cli/src/builtin/interface.d.ts +3 -2
- package/dist/cli/src/builtin/modules/number-theory/sequences/index.d.ts +2 -1
- package/dist/cli/src/evaluator/functionExecutors.d.ts +2 -1
- package/dist/cli/src/evaluator/index.d.ts +3 -2
- package/dist/cli/src/evaluator/interface.d.ts +3 -2
- package/dist/cli/src/utils/maybePromise.d.ts +54 -0
- package/dist/full.esm.js +1 -1
- package/dist/full.esm.js.map +1 -1
- package/dist/full.js +1 -1
- package/dist/full.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +1 -1
- package/dist/lits.iife.js.map +1 -1
- package/dist/modules/assert.esm.js +1 -1
- package/dist/modules/assert.esm.js.map +1 -1
- package/dist/modules/assert.js +1 -1
- package/dist/modules/assert.js.map +1 -1
- package/dist/modules/collection.esm.js +1 -1
- package/dist/modules/collection.esm.js.map +1 -1
- package/dist/modules/collection.js +1 -1
- package/dist/modules/collection.js.map +1 -1
- package/dist/modules/grid.esm.js +1 -1
- package/dist/modules/grid.esm.js.map +1 -1
- package/dist/modules/grid.js +1 -1
- package/dist/modules/grid.js.map +1 -1
- package/dist/modules/number-theory.esm.js +1 -1
- package/dist/modules/number-theory.esm.js.map +1 -1
- package/dist/modules/number-theory.js +1 -1
- package/dist/modules/number-theory.js.map +1 -1
- package/dist/modules/sequence.esm.js +1 -1
- package/dist/modules/sequence.esm.js.map +1 -1
- package/dist/modules/sequence.js +1 -1
- package/dist/modules/sequence.js.map +1 -1
- package/dist/modules/src/Lits/Lits.d.ts +8 -2
- package/dist/modules/src/builtin/bindingNode.d.ts +2 -1
- package/dist/modules/src/builtin/interface.d.ts +3 -2
- package/dist/modules/src/builtin/modules/number-theory/sequences/index.d.ts +2 -1
- package/dist/modules/src/evaluator/functionExecutors.d.ts +2 -1
- package/dist/modules/src/evaluator/index.d.ts +3 -2
- package/dist/modules/src/evaluator/interface.d.ts +3 -2
- package/dist/modules/src/utils/maybePromise.d.ts +54 -0
- package/dist/modules/vector.esm.js +1 -1
- package/dist/modules/vector.esm.js.map +1 -1
- package/dist/modules/vector.js +1 -1
- package/dist/modules/vector.js.map +1 -1
- package/dist/src/Lits/Lits.d.ts +8 -2
- package/dist/src/builtin/bindingNode.d.ts +2 -1
- package/dist/src/builtin/interface.d.ts +3 -2
- package/dist/src/builtin/modules/number-theory/sequences/index.d.ts +2 -1
- package/dist/src/evaluator/functionExecutors.d.ts +2 -1
- package/dist/src/evaluator/index.d.ts +3 -2
- package/dist/src/evaluator/interface.d.ts +3 -2
- package/dist/src/utils/maybePromise.d.ts +54 -0
- package/dist/testFramework.esm.js +1 -1
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +1 -1
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/dist/modules/grid.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e){if(!e.position||!e.code)return"";const t=e.position.column-1,r=e.code.length-t-1;return`${" ".repeat(Math.max(t,0))}^${" ".repeat(Math.max(r,0))}`}class t extends Error{sourceCodeInfo;shortMessage;constructor(r,n){const i=r instanceof Error?r.message:`${r}`;super(function(t,r){if(!r)return t;const n=`${r.position.line}:${r.position.column}`;return`${t}${r.filePath?`\n${r.filePath}:${n}`:`\nLocation ${n}`}\n${r.code}\n${e(r)}`}(i,n)),this.shortMessage=i,this.sourceCodeInfo=n,Object.setPrototypeOf(this,t.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&e(this.sourceCodeInfo)}}const r={Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10},n=new Set(Object.values(r));const i=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);const o="^^fn^^",s="^^re^^";function a(e){return null!==e&&"object"==typeof e&&(o in e&&"functionType"in e&&("string"==typeof(t=e.functionType)&&i.has(t)));var t}function l(e){return!(!Array.isArray(e)||e.length<2)&&("number"==typeof(t=e[0])&&n.has(t));var t}function g(e){return a(e)?`<function ${e.name||"λ"}>`:l(e)?`${t=e[0],Object.keys(r).find(e=>r[e]===t)}-node`:null===e?"null":"object"==typeof e&&e instanceof RegExp?`${e}`:"object"==typeof e&&e instanceof Error?e.toString():JSON.stringify(e);var t}function d(e,t){return e?.sourceCodeInfo??t}function c(e,t={}){return"number"==typeof e&&(!Number.isNaN(e)&&(!(t.integer&&!Number.isInteger(e))&&(!(t.finite&&!Number.isFinite(e))&&((!t.zero||0===e)&&((!t.nonZero||0!==e)&&(!(t.positive&&e<=0)&&(!(t.negative&&e>=0)&&(!(t.nonPositive&&e>0)&&(!(t.nonNegative&&e<0)&&(!("number"==typeof t.gt&&e<=t.gt)&&(!("number"==typeof t.gte&&e<t.gte)&&(!("number"==typeof t.lt&&e>=t.lt)&&!("number"==typeof t.lte&&e>t.lte)))))))))))))}function u(e,r,n={}){if(!c(e,n))throw new t(`Expected ${function(e){if(e.zero)return"zero";const t=function(e){return e.positive?"positive":e.negative?"negative":e.nonNegative?"non negative":e.nonPositive?"non positive":e.nonZero?"non zero":""}(e),r=e.integer?"integer":"number",n=e.finite?"finite":"",i=function(e){return"number"!=typeof e.gt&&"number"!=typeof e.gte||"number"!=typeof e.lt&&"number"!=typeof e.lte?"number"==typeof e.gt||"number"==typeof e.gte?"number"==typeof e.gt?`n > ${e.gt}`:`n >= ${e.gte}`:"number"==typeof e.lt||"number"==typeof e.lte?"number"==typeof e.lt?`n < ${e.lt}`:`n <= ${e.lte}`:"":`${"number"==typeof e.gt?`${e.gt} < n `:`${e.gte} <= n `}${"number"==typeof e.lt?`< ${e.lt}`:`<= ${e.lte}`}`}(e);return[t,n,r,i].filter(e=>!!e).join(" ")}(n)}, got ${g(e)}.`,d(e,r))}const h=new WeakSet,p=new WeakSet,m=new WeakSet,f=new WeakSet,y=new WeakSet;function b(e,r){if(!function(e){return!(!Array.isArray(e)||!p.has(e)&&(m.has(e)||(e.every(e=>c(e))?(h.add(e),p.add(e),0):(m.add(e),1))))}(e))throw new t(`Expected a vector, but got ${e}`,r)}function v(e,r){if(!function(e){if(!Array.isArray(e))return!1;if(f.has(e))return!0;if(y.has(e))return!1;if(0===e.length)return y.add(e),!1;if(!Array.isArray(e[0]))return y.add(e),!1;const t=e[0].length;for(const r of e.slice(1)){if(!Array.isArray(r))return y.add(e),!1;if(r.length!==t)return y.add(e),!1}return h.add(e),f.add(e),!0}(e))throw new t(`Expected a grid, but got ${e}`,r)}function w(e,r,n){return new t(`Expected ${e}, got ${g(r)}.`,d(r,n))}function A(e,t){if(!Array.isArray(e))throw w("array",e,t)}function N(e){return null!==e&&"object"==typeof e&&!!e[o]}function x(e,t){return $(e,t),e}function $(e,t){if(!function(e){return void 0!==e}(e))throw w("not undefined",e,t)}function T(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof RegExp||N(e)||(t=e,null!==t&&"object"==typeof t&&t[s]));var t}function K(e){return function(e){return Array.isArray(e)||"string"==typeof e}(e)||T(e)}function C(e,t){if(!function(e){return"number"==typeof e||!!K(e)||!!N(e)}(e))throw w("FunctionLike",e,t)}function F(e){return{min:e,max:e}}const S={"every?":{category:"grid",description:"Checks if all elements in a grid satisfy a predicate. Returns true only if the predicate returns true for every element in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['// Using "as" alias because "every?" shadows a builtin function\nlet { every? as grid-every? } = import("grid");\ngrid-every?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], string?)','// Using "as" alias because "every?" shadows a builtin function\nlet { every? as grid-every? } = import("grid");\ngrid-every?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], string?)','// Using "as" alias because "every?" shadows a builtin function\nlet { every? as grid-every? } = import("grid");\ngrid-every?([\n [1, 2],\n [3, 4],\n], string?)'],seeAlso:["collection.every?","grid.some?","grid.every-row?","grid.every-col?"]},"some?":{category:"grid",description:"Checks if any element in a grid satisfies a predicate. Returns true if the predicate returns true for at least one element in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some? } = import("grid");\nsome?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], string?)','let { some? } = import("grid");\nsome?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], string?)','let { some? } = import("grid");\nsome?([\n [1, 2],\n [3, 4],\n], string?)'],seeAlso:["collection.any?","grid.every?","grid.some-row?","grid.some-col?"]},"every-row?":{category:"grid",description:"Checks if all rows in a grid satisfy a predicate. Returns true only if the predicate returns true for every row in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { every-row? } = import("grid");\nevery-row?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> string?($[0]))','let { every-row? } = import("grid");\nevery-row?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> string?($[0]))','let { every-row? } = import("grid");\nevery-row?([\n [1, 2],\n [3, 4],\n], -> string?($[0]))'],seeAlso:["grid.some-row?","grid.every-col?","grid.every?"]},"some-row?":{category:"grid",description:"Checks if any row in a grid satisfies a predicate. Returns true if the predicate returns true for at least one row in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some-row? } = import("grid");\nsome-row?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $ contains? "Albert")','let { some-row? } = import("grid");\nsome-row?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> $ contains? "Albert")','let { some-row? } = import("grid");\nsome-row?([\n [1, 2],\n [3, 4],\n], -> $ contains? "Albert")'],seeAlso:["grid.every-row?","grid.some-col?","grid.some?"]},"every-col?":{category:"grid",description:"Checks if all columns in a grid satisfy a predicate. Returns true only if the predicate returns true for every column in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { every-col? } = import("grid");\nevery-col?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> string?($[0]))','let { every-col? } = import("grid");\nevery-col?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> string?($[0]))','let { every-col? } = import("grid");\nevery-col?([\n [1, 2],\n [3, 4],\n], -> string?($[0]))'],seeAlso:["grid.some-col?","grid.every-row?","grid.every?"]},"some-col?":{category:"grid",description:"Checks if any column in a grid satisfies a predicate. Returns true if the predicate returns true for at least one column in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some-col? } = import("grid");\nsome-col?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $ contains? "Albert")','let { some-col? } = import("grid");\nsome-col?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> $ contains? "Albert")','let { some-col? } = import("grid");\nsome-col?([\n [1, 2],\n [3, 4],\n], -> $ contains? "Albert")'],seeAlso:["grid.every-col?","grid.some-row?","grid.some?"]},row:{category:"grid",description:"Returns the row at index $a in the grid $b.",returns:{type:"any"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { row } = import("grid");\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 0)','let { row } = import("grid");\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)','let { row } = import("grid");\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 2)'],seeAlso:["grid.col","grid.shape"]},col:{category:"grid",description:"Returns the column at index $a in the grid $b.",returns:{type:"any"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { col } = import("grid");\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 0)','let { col } = import("grid");\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)','let { col } = import("grid");\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 2)'],seeAlso:["grid.row","grid.shape"]},shape:{category:"grid",description:"Returns the shape of the grid `g` as a `vector` of two numbers, where the first number is the number of rows and the second number is the number of columns.",returns:{type:"vector"},args:{g:{type:"grid",description:"The grid to get the shape of."}},variants:[{argumentNames:["g"]}],examples:['let { shape } = import("grid");\nshape([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { shape } = import("grid");\nshape([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])','let { shape } = import("grid");\nshape([\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.row","grid.col","grid.reshape"]},fill:{category:"grid",description:"Creates a grid of the specified size, filled with the specified value.",returns:{type:"grid"},args:{rows:{type:"integer",description:"The number of rows in the grid."},cols:{type:"integer",description:"The number of columns in the grid."},value:{type:"any",description:"The value to fill the grid with."}},variants:[{argumentNames:["rows","cols","value"]}],examples:['let { fill } = import("grid");\nfill(2, 3, 0)','let { fill } = import("grid");\nfill(2, 3, "x")'],seeAlso:["grid.generate","grid.from-array","vector.fill"]},generate:{category:"grid",description:"Generates a grid of the specified size, where each element is generated by the provided function.",returns:{type:"grid"},args:{rows:{type:"number",description:"The number of rows in the grid."},cols:{type:"number",description:"The number of columns in the grid."},fn:{type:"function",description:"The function to generate the grid. It takes two arguments: the row index and the column index."}},variants:[{argumentNames:["rows","cols","fn"]}],examples:['let { generate } = import("grid");\ngenerate(3, 3, (i, j) -> i + j)'],seeAlso:["grid.fill","grid.from-array","vector.generate"]},reshape:{category:"grid",description:"Reshapes the grid `a` into a new grid with the specified number of rows `b`. The number of columns is automatically calculated based on the total number of elements in the grid.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { reshape } = import("grid");\nreshape([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], 2)'],seeAlso:["grid.shape","grid.from-array"]},transpose:{category:"grid",description:"Transposes the grid `g`, swapping its rows and columns.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to transpose."}},variants:[{argumentNames:["g"]}],examples:['let { transpose } = import("grid");\ntranspose([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { transpose } = import("grid");\ntranspose([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])','let { transpose } = import("grid");\ntranspose([\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.flip-h","grid.flip-v","grid.rotate"]},"flip-h":{category:"grid",description:"Flips the grid `g` horizontally.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to flip horizontally."}},variants:[{argumentNames:["g"]}],examples:['let { flip-h } = import("grid");\nflip-h([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { flip-h } = import("grid");\nflip-h([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])','let { flip-h } = import("grid");\nflip-h([\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.flip-v","grid.transpose","grid.rotate","grid.reverse-cols"]},"flip-v":{category:"grid",description:"Flips the grid `g` vertically.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to flip vertically."}},variants:[{argumentNames:["g"]}],examples:['let { flip-v } = import("grid");\nflip-v([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { flip-v } = import("grid");\nflip-v([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])','let { flip-v } = import("grid");\nflip-v([\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.flip-h","grid.transpose","grid.rotate","grid.reverse-rows"]},rotate:{category:"grid",description:"Rotates the grid `g` by the specified angle. The angle is given in terms of 90-degree rotations. Positive values rotate the grid clockwise, while negative values rotate it counterclockwise.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:['let { rotate } = import("grid");\nrotate([\n [1, 2],\n [3, 4],\n], 1)','let { rotate } = import("grid");\nrotate([\n [1, 2],\n [3, 4],\n], 2)','let { rotate } = import("grid");\nrotate([\n [1, 2],\n [3, 4],\n], 3)','let { rotate } = import("grid");\nrotate([\n [1, 2],\n [3, 4],\n], 4)','let { rotate } = import("grid");\nrotate([\n [1, 2],\n [3, 4],\n], -1)','let { rotate } = import("grid");\nrotate([\n [1, 2],\n [3, 4],\n], -2)','let { rotate } = import("grid");\nrotate([\n [1, 2],\n [3, 4],\n], -3)'],seeAlso:["grid.transpose","grid.flip-h","grid.flip-v"]},"reverse-rows":{category:"grid",description:"Reverses the order of rows in the grid `g`.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to reverse rows."}},variants:[{argumentNames:["g"]}],examples:['let { reverse-rows } = import("grid");\nreverse-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { reverse-rows } = import("grid");\nreverse-rows([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])','let { reverse-rows } = import("grid");\nreverse-rows([\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.reverse-cols","grid.flip-v"]},"reverse-cols":{category:"grid",description:"Reverses the order of columns in the grid `g`.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to reverse columns."}},variants:[{argumentNames:["g"]}],examples:['let { reverse-cols } = import("grid");\nreverse-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { reverse-cols } = import("grid");\nreverse-cols([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])','let { reverse-cols } = import("grid");\nreverse-cols([\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.reverse-rows","grid.flip-h"]},slice:{category:"grid",description:"Slices the grid `g` from the starting index `begin` to the optional ending index `stop`. The slice is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"vector",description:"The starting index of the slice as a vector of two numbers: `[row, col]`."},stop:{type:"vector",description:"Optional ending index of the slice as a vector of two numbers: `[row, col]`."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['// Using "as" alias because "slice" shadows a builtin function\nlet { slice as grid-slice } = import("grid");\ngrid-slice([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [1, 1], [2, 2])','// Using "as" alias because "slice" shadows a builtin function\nlet { slice as grid-slice } = import("grid");\ngrid-slice([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [1, 1])'],hideOperatorForm:!0,seeAlso:["grid.slice-rows","grid.slice-cols"]},"slice-rows":{category:"grid",description:"Slices rows of the grid `g` from the starting index `begin` to the optional ending index `stop`. The slice is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"number",description:"The starting index of the slice."},stop:{type:"number",description:"Optional ending index of the slice."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['let { slice-rows } = import("grid");\nslice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { slice-rows } = import("grid");\nslice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)'],hideOperatorForm:!0,seeAlso:["grid.slice","grid.slice-cols","grid.splice-rows"]},"slice-cols":{category:"grid",description:"Slices columns of the grid `g` from the starting index `begin` to the optional ending index `stop`. The slice is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"number",description:"The starting index of the slice."},stop:{type:"number",description:"Optional ending index of the slice."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['let { slice-cols } = import("grid");\nslice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { slice-cols } = import("grid");\nslice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)'],hideOperatorForm:!0,seeAlso:["grid.slice","grid.slice-rows","grid.splice-cols"]},"splice-rows":{category:"grid",description:"Splices rows of the grid `g` starting from the index `begin`. Deletes `deleteCount` rows and inserts the specified `items` at that position.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to splice."},begin:{type:"number",description:"The starting index of the splice."},deleteCount:{type:"number",description:"The number of rows to delete."},items:{type:"array",rest:!0,description:"The rows to insert."}},variants:[{argumentNames:["g","begin","deleteCount"]},{argumentNames:["g","begin","deleteCount","items"]}],examples:['let { splice-rows } = import("grid");\nsplice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { splice-rows } = import("grid");\nsplice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 1, ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.splice-cols","grid.slice-rows"]},"splice-cols":{category:"grid",description:"Splices columns of the grid `g` starting from the index `begin`. Deletes `deleteCount` columns and inserts the specified `items` at that position.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to splice."},begin:{type:"number",description:"The starting index of the splice."},deleteCount:{type:"number",description:"The number of columns to delete."},items:{type:"array",rest:!0,description:"The columns to insert."}},variants:[{argumentNames:["g","begin","deleteCount"]},{argumentNames:["g","begin","deleteCount","items"]}],examples:['let { splice-cols } = import("grid");\nsplice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { splice-cols } = import("grid");\nsplice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 1, ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.splice-rows","grid.slice-cols"]},"concat-rows":{category:"grid",description:"Concatenates two grids `a` and `b` by rows. The number of columns in both grids must be the same.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"grid"}},variants:[{argumentNames:["a","b"]}],examples:['let { concat-rows } = import("grid");\nconcat-rows([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], [\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.concat-cols","grid.push-rows"]},"concat-cols":{category:"grid",description:"Concatenates two grids `a` and `b` by columns. The number of rows in both grids must be the same.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"grid"}},variants:[{argumentNames:["a","b"]}],examples:['let { concat-cols } = import("grid");\nconcat-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])'],seeAlso:["grid.concat-rows","grid.push-cols"]},map:{category:"grid",description:"Maps a function `a` over each element of the grid `b`, returning a new grid with the results.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['// Using "as" alias because "map" shadows a builtin function\nlet { map as grid-map } = import("grid");\ngrid-map([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], str)'],seeAlso:["map","grid.mapi","grid.reduce"]},mapi:{category:"grid",description:"Maps a function `a` over each element of the grid `b`, passing the row and column index as additional arguments to the function.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['// Using "as" alias because "mapi" shadows a builtin function\nlet { mapi as grid-mapi } = import("grid");\ngrid-mapi([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $1 ++ "(" ++ $2 ++ ", " ++ $3 ++ ")")'],seeAlso:["grid.map","grid.reducei","map"]},reduce:{category:"grid",description:"Reduces the grid `a` using the function `b`, returning a single value.",returns:{type:"any"},args:{g:{type:"grid",description:"The grid to reduce."},fn:{type:"function",description:"The function to reduce the grid. It takes two arguments: the accumulator and the current element."},"initial-value":{type:"any",description:"The initial value for the accumulator."}},variants:[{argumentNames:["g","fn","initial-value"]}],examples:['// Using "as" alias because "reduce" shadows a builtin function\nlet { reduce as grid-reduce } = import("grid");\ngrid-reduce([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ++, "")'],seeAlso:["reduce","grid.reducei","grid.map"]},reducei:{category:"grid",description:"Reduces the grid `a` using the function `b`, passing the row and column indices as additional arguments to the function.",returns:{type:"any"},args:{g:{type:"grid",description:"The grid to reduce."},fn:{type:"function",description:"The function to reduce the grid. It takes four arguments: the accumulator, the current element, the row index, and the column index."},"initial-value":{type:"any",description:"The initial value for the accumulator."}},variants:[{argumentNames:["g","fn","initial-value"]}],examples:['// Using "as" alias because "reducei" shadows a builtin function\nlet { reducei as grid-reducei } = import("grid");\ngrid-reducei([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ++, "")'],seeAlso:["grid.reduce","grid.mapi","reduce"]},"push-rows":{category:"grid",description:"Pushes the specified rows into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to push rows into."},rows:{type:"array",rest:!0,description:"The rows to push into the grid."}},variants:[{argumentNames:["g","rows"]}],examples:['let { push-rows } = import("grid");\npush-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.unshift-rows","grid.pop-row","grid.shift-row","grid.concat-rows"]},"unshift-rows":{category:"grid",description:"Unshifts the specified rows into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to unshift rows into."},rows:{type:"array",rest:!0,description:"The rows to unshift into the grid."}},variants:[{argumentNames:["g","rows"]}],examples:['let { unshift-rows } = import("grid");\nunshift-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.push-rows","grid.shift-row","grid.pop-row"]},"pop-row":{category:"grid",description:"Pops the last row from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to pop a row from."}},variants:[{argumentNames:["g"]}],examples:['let { pop-row } = import("grid");\npop-row([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.shift-row","grid.push-rows","grid.unshift-rows"]},"shift-row":{category:"grid",description:"Shifts the first row from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to shift a row from."}},variants:[{argumentNames:["g"]}],examples:['let { shift-row } = import("grid");\nshift-row([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.pop-row","grid.push-rows","grid.unshift-rows"]},"push-cols":{category:"grid",description:"Pushes the specified columns into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to push columns into."},cols:{type:"array",rest:!0,description:"The columns to push into the grid."}},variants:[{argumentNames:["g","cols"]}],examples:['let { push-cols } = import("grid");\npush-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.unshift-cols","grid.pop-col","grid.shift-col","grid.concat-cols"]},"unshift-cols":{category:"grid",description:"Unshifts the specified columns into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to unshift columns into."},cols:{type:"array",rest:!0,description:"The columns to unshift into the grid."}},variants:[{argumentNames:["g","cols"]}],examples:['let { unshift-cols } = import("grid");\nunshift-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.push-cols","grid.shift-col","grid.pop-col"]},"pop-col":{category:"grid",description:"Pops the last column from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to pop a column from."}},variants:[{argumentNames:["g"]}],examples:['let { pop-col } = import("grid");\npop-col([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.shift-col","grid.push-cols","grid.unshift-cols"]},"shift-col":{category:"grid",description:"Shifts the first column from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to shift a column from."}},variants:[{argumentNames:["g"]}],examples:['let { shift-col } = import("grid");\nshift-col([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.pop-col","grid.push-cols","grid.unshift-cols"]},"from-array":{category:"grid",description:"Creates a grid from a flat array with specified dimensions. The array is reshaped into the specified number of rows, and the number of columns is automatically calculated based on the total number of elements in the array.",returns:{type:"grid"},args:{a:{type:"array"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { from-array } = import("grid");\nfrom-array([1, 2, 3, 4], 2)','let { from-array } = import("grid");\nfrom-array([1, 2, 3, 4], 4)'],seeAlso:["grid.fill","grid.generate","grid.reshape"]}};function k(e){const t=[];for(let r=0;r<e[0].length;r+=1){const n=[];for(let t=0;t<e.length;t+=1)n.push(e[t][r]);t.push(n)}return t}const E={"every?":{evaluate:([e,t],r,n,{executeFunction:i})=>{v(e,r),C(t,r);for(const o of e)for(const e of o)if(!i(t,[e],n,r))return!1;return!0},arity:F(2)},"some?":{evaluate:([e,t],r,n,{executeFunction:i})=>{v(e,r),C(t,r);for(const o of e)for(const e of o)if(i(t,[e],n,r))return!0;return!1},arity:F(2)},"every-row?":{evaluate:([e,t],r,n,{executeFunction:i})=>{v(e,r),C(t,r);for(const o of e)if(!i(t,[o],n,r))return!1;return!0},arity:F(2)},"some-row?":{evaluate:([e,t],r,n,{executeFunction:i})=>{v(e,r),C(t,r);for(const o of e)if(i(t,[o],n,r))return!0;return!1},arity:F(2)},"every-col?":{evaluate:([e,t],r,n,{executeFunction:i})=>{v(e,r),C(t,r);const o=k(e);for(const e of o)if(!i(t,[e],n,r))return!1;return!0},arity:F(2)},"some-col?":{evaluate:([e,t],r,n,{executeFunction:i})=>{v(e,r),C(t,r);const o=k(e);for(const e of o)if(i(t,[e],n,r))return!0;return!1},arity:F(2)},row:{evaluate:([e,t],r)=>(v(e,r),u(t,r,{integer:!0,nonNegative:!0,lt:e.length}),e[t]),arity:F(2)},col:{evaluate:([e,t],r)=>(v(e,r),u(t,r,{integer:!0,nonNegative:!0,lt:e[0].length}),e.map(e=>e[t])),arity:F(2)},shape:{evaluate:([e],t)=>(v(e,t),[e.length,e[0].length]),arity:F(1)},fill:{evaluate:([e,t,r],n)=>{u(e,n,{integer:!0,positive:!0}),u(t,n,{integer:!0,positive:!0}),$(r,n);const i=[];for(let n=0;n<e;n+=1){const e=[];for(let n=0;n<t;n+=1)e.push(r);i.push(e)}return i},arity:F(3)},generate:{evaluate:([e,t,r],n,i,{executeFunction:o})=>{u(e,n,{integer:!0,positive:!0}),u(t,n,{integer:!0,positive:!0}),C(r,n);const s=[];for(let a=0;a<e;a+=1){const e=[];for(let s=0;s<t;s+=1){const t=o(r,[a,s],i,n);$(t,n),e.push(t)}s.push(e)}return s},arity:F(3)},reshape:{evaluate:([e,r],n)=>{v(e,n),u(r,n,{integer:!0,positive:!0});const i=e.flat();if(i.length%r!==0)throw new t(`The number of elements in the grid must be divisible by rows, but got ${i.length} and ${r}`,n);const o=i.length/r,s=[];for(let e=0;e<r;e+=1){const t=[];for(let r=0;r<o;r+=1)t.push(i[e*o+r]);s.push(t)}return s},arity:F(2)},transpose:{evaluate:([e],t)=>(v(e,t),k(e)),arity:F(1)},"flip-h":{evaluate:([e],t)=>(v(e,t),e.map(e=>e.reverse())),arity:F(1)},"flip-v":{evaluate:([e],t)=>(v(e,t),e.reverse()),arity:F(1)},rotate:{evaluate:([e,t],r)=>{if(v(e,r),u(t,r,{integer:!0}),0===(t=(t%4+4)%4)||0===e.length)return e.map(e=>[...e]);const n=e.length,i=e[0].length;let o;switch(t){case 1:o=Array(i).fill(null).map(()=>Array(n).fill(null));for(let t=0;t<n;t++)for(let r=0;r<i;r++)o[r][n-1-t]=e[t][r];break;case 2:o=Array(n).fill(null).map(()=>Array(i).fill(null));for(let t=0;t<n;t++)for(let r=0;r<i;r++)o[n-1-t][i-1-r]=e[t][r];break;case 3:o=Array(i).fill(null).map(()=>Array(n).fill(null));for(let t=0;t<n;t++)for(let r=0;r<i;r++)o[i-1-r][t]=e[t][r]}return o},arity:F(2)},"reverse-rows":{evaluate:([e],t)=>(v(e,t),e.reverse()),arity:F(1)},"reverse-cols":{evaluate:([e],t)=>(v(e,t),e.map(e=>e.reverse())),arity:F(1)},slice:{evaluate:([e,r,n],i)=>{if(v(e,i),b(r,i),2!==r.length)throw new t(`The start vector must have 2 elements, but got ${r.length}`,i);const[o,s]=r;if(u(o,i,{integer:!0,nonNegative:!0,lt:e.length}),u(s,i,{integer:!0,nonNegative:!0,lt:e[0].length}),n??=[e.length,e[0].length],b(n,i),2!==n.length)throw new t(`The end vector must have 2 elements, but got ${n.length}`,i);const[a,l]=n;u(a,i,{gt:o,lte:e.length}),u(l,i,{gt:s,lte:e[0].length});const g=[];for(let t=o;t<a;t+=1){const r=[];for(let n=s;n<l;n+=1)r.push(e[t][n]);g.push(r)}return g},arity:{min:2,max:3}},"slice-rows":{evaluate:([e,t,r],n)=>(v(e,n),void 0===r?(u(t,n,{integer:!0,lte:e.length,gte:-e.length}),t<0?e.slice(e.length+t):e.slice(t)):(u(t,n,{integer:!0,nonNegative:!0,lte:e.length}),u(r,n,{integer:!0}),u(r=r<0?e.length+r:r,n,{gt:t,lte:e.length}),e.slice(t,r))),arity:{min:2,max:3}},"slice-cols":{evaluate:([e,t,r],n)=>{v(e,n);const i=k(e);return void 0===r?(u(t,n,{integer:!0,lte:i.length,gte:-i.length}),k(t<0?i.slice(i.length+t):i.slice(t))):(u(t,n,{integer:!0,nonNegative:!0,lte:i.length}),u(r,n,{integer:!0}),u(r=r<0?i.length+r:r,n,{gt:t,lte:i.length}),k(i.slice(t,r)))},arity:{min:2,max:3}},"splice-rows":{evaluate:([e,r,n,...i],o)=>{v(e,o),u(r,o,{integer:!0,nonNegative:!0,lte:e.length}),u(n,o,{integer:!0,nonNegative:!0}),0!==i.length&&(v(i,o),i.every(r=>{if(A(r,o),e[0].length!==r.length)throw new t(`All rows must have the same length as the number of columns in grid, but got ${r.length}`,o);return!0}));const s=[];for(let t=0;t<r;t+=1)s.push(e[t]);i.length>0&&s.push(...i);for(let t=r+n;t<e.length;t+=1)s.push(e[t]);return s},arity:{min:3}},"splice-cols":{evaluate:([e,r,n,...i],o)=>{v(e,o);const s=k(e);u(r,o,{integer:!0,nonNegative:!0,lte:s.length}),u(n,o,{integer:!0,nonNegative:!0}),0!==i.length&&(v(i,o),i.every(e=>{if(A(e,o),s[0].length!==e.length)throw new t(`All rows must have the same length as the number of rows in grid, but got ${e.length}`,o);return!0}));const a=[];for(let e=0;e<r;e+=1)a.push(s[e]);a.push(...i);for(let e=r+n;e<s.length;e+=1)a.push(s[e]);return k(a)},arity:{min:3}},"concat-rows":{evaluate:(e,r)=>{A(e,r),e.every(e=>v(e,r));const n=e[0][0].length;e.slice(1).every(e=>{if(e[0].length!==n)throw new t(`All grids must have the same number of columns, but got ${n} and ${e[0].length}`,r);return!0});const i=[];return e.forEach(e=>{e.forEach(e=>{i.push(e)})}),i},arity:{min:1}},"concat-cols":{evaluate:(e,r)=>{A(e,r),e.every(e=>v(e,r));const n=e[0].length;e.slice(1).every(e=>{if(e.length!==n)throw new t(`All grids must have the same number of rows, but got ${n} and ${e.length}`,r);return!0});const i=[];for(let t=0;t<n;t+=1){const r=[];e.forEach(e=>{r.push(...e[t])}),i.push(r)}return i},arity:{min:1}},map:{evaluate:(e,r,n,{executeFunction:i})=>{const o=function(e,t){return C(e,t),e}(e.at(-1),r),s=e.slice(0,-1);v(s[0],r);const a=s[0].length,l=s[0][0].length;s.slice(1).forEach(e=>{if(v(e,r),e.length!==a)throw new t(`All grids must have the same number of rows, but got ${a} and ${e.length}`,r);if(e[0].length!==l)throw new t(`All grids must have the same number of columns, but got ${l} and ${e[0].length}`,r)});const g=[];for(let e=0;e<a;e+=1){const t=[];for(let a=0;a<l;a+=1){const l=s.map(t=>t[e][a]);t.push(x(i(o,l,n,r)))}g.push(t)}return g},arity:{min:2}},mapi:{evaluate:([e,t],r,n,{executeFunction:i})=>{v(e,r),C(t,r);const o=e.length,s=e[0].length,a=[];for(let l=0;l<o;l+=1){const o=[];for(let a=0;a<s;a+=1)o.push(x(i(t,[e[l][a],l,a],n,r)));a.push(o)}return a},arity:F(2)},reduce:{evaluate:([e,t,r],n,i,{executeFunction:o})=>{v(e,n),C(t,n);let s=x(r);for(const r of e)for(const e of r)s=o(t,[s,e],i,n);return s},arity:F(3)},reducei:{evaluate:([e,t,r],n,i,{executeFunction:o})=>{v(e,n),C(t,n);let s=x(r);for(let r=0;r<e.length;r+=1)for(let a=0;a<e[r].length;a+=1)s=o(t,[s,e[r][a],r,a],i,n);return s},arity:F(3)},"push-rows":{evaluate:([e,...r],n)=>{if(v(e,n),v(r,n),e[0].length!==r[0].length)throw new t(`All rows must have the same length as the number of columns in grid, but got ${e[0].length} and ${r[0].length}`,n);return[...e,...r]},arity:{min:2}},"unshift-rows":{evaluate:([e,...r],n)=>{if(v(e,n),v(r,n),e[0].length!==r[0].length)throw new t(`All rows must have the same length as the number of columns in grid, but got ${e[0].length} and ${r[0].length}`,n);return[...r,...e]},arity:{min:2}},"pop-row":{evaluate:([e],t)=>(v(e,t),1===e.length?null:e.slice(0,-1)),arity:F(1)},"shift-row":{evaluate:([e],t)=>(v(e,t),1===e.length?null:e.slice(1)),arity:F(1)},"push-cols":{evaluate:([e,...r],n)=>{if(v(e,n),v(r,n),e.length!==r[0].length)throw new t(`All columns must have the same length as the number of rows in grid, but got ${r.length}`,n);const i=[];for(let t=0;t<e.length;t+=1){const n=[];n.push(...e[t]),r.forEach(e=>{n.push(e[t])}),i.push(n)}return i},arity:{min:2}},"unshift-cols":{evaluate:([e,...r],n)=>{if(v(e,n),v(r,n),e.length!==r[0].length)throw new t(`All columns must have the same length as the number of rows in grid, but got ${r.length}`,n);const i=[];for(let t=0;t<e.length;t+=1){const n=[];r.forEach(e=>{n.push(e[t])}),n.push(...e[t]),i.push(n)}return i},arity:{min:2}},"pop-col":{evaluate:([e],t)=>(v(e,t),1===e[0].length?null:e.map(e=>e.slice(0,-1))),arity:F(1)},"shift-col":{evaluate:([e],t)=>(v(e,t),1===e[0].length?null:e.map(e=>e.slice(1))),arity:F(1)},"from-array":{evaluate:([e,r],n)=>{if(A(e,n),u(r,n,{integer:!0,positive:!0}),e.length%r!==0)throw new t(`The number of elements in the array must be divisible by rows, but got ${e.length} and ${r}`,n);return function(e,t){const r=[],n=e.length/t;for(let i=0;i<t;i++){const t=i*n,o=t+n;r.push(e.slice(t,o))}return r}(e,r)},arity:F(2)}};for(const[e,t]of Object.entries(S))E[e]&&(E[e].docs=t);const O={name:"grid",functions:E};export{O as gridModule};
|
|
1
|
+
function e(e){if(!e.position||!e.code)return"";const r=e.position.column-1,t=e.code.length-r-1;return`${" ".repeat(Math.max(r,0))}^${" ".repeat(Math.max(t,0))}`}class r extends Error{sourceCodeInfo;shortMessage;constructor(t,n){const i=t instanceof Error?t.message:`${t}`;super(function(r,t){if(!t)return r;const n=`${t.position.line}:${t.position.column}`;return`${r}${t.filePath?`\n${t.filePath}:${n}`:`\nLocation ${n}`}\n${t.code}\n${e(t)}`}(i,n)),this.shortMessage=i,this.sourceCodeInfo=n,Object.setPrototypeOf(this,r.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&e(this.sourceCodeInfo)}}const t={Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10},n=new Set(Object.values(t));const i=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);const o="^^fn^^",s="^^re^^";function a(e){return null!==e&&"object"==typeof e&&(o in e&&"functionType"in e&&("string"==typeof(r=e.functionType)&&i.has(r)));var r}function l(e){return!(!Array.isArray(e)||e.length<2)&&("number"==typeof(r=e[0])&&n.has(r));var r}function g(e){return a(e)?`<function ${e.name||"λ"}>`:l(e)?`${r=e[0],Object.keys(t).find(e=>t[e]===r)}-node`:null===e?"null":"object"==typeof e&&e instanceof RegExp?`${e}`:"object"==typeof e&&e instanceof Error?e.toString():JSON.stringify(e);var r}function c(e,r){return e?.sourceCodeInfo??r}function d(e,r={}){return"number"==typeof e&&(!Number.isNaN(e)&&(!(r.integer&&!Number.isInteger(e))&&(!(r.finite&&!Number.isFinite(e))&&((!r.zero||0===e)&&((!r.nonZero||0!==e)&&(!(r.positive&&e<=0)&&(!(r.negative&&e>=0)&&(!(r.nonPositive&&e>0)&&(!(r.nonNegative&&e<0)&&(!("number"==typeof r.gt&&e<=r.gt)&&(!("number"==typeof r.gte&&e<r.gte)&&(!("number"==typeof r.lt&&e>=r.lt)&&!("number"==typeof r.lte&&e>r.lte)))))))))))))}function u(e,t,n={}){if(!d(e,n))throw new r(`Expected ${function(e){if(e.zero)return"zero";const r=function(e){return e.positive?"positive":e.negative?"negative":e.nonNegative?"non negative":e.nonPositive?"non positive":e.nonZero?"non zero":""}(e),t=e.integer?"integer":"number",n=e.finite?"finite":"",i=function(e){return"number"!=typeof e.gt&&"number"!=typeof e.gte||"number"!=typeof e.lt&&"number"!=typeof e.lte?"number"==typeof e.gt||"number"==typeof e.gte?"number"==typeof e.gt?`n > ${e.gt}`:`n >= ${e.gte}`:"number"==typeof e.lt||"number"==typeof e.lte?"number"==typeof e.lt?`n < ${e.lt}`:`n <= ${e.lte}`:"":`${"number"==typeof e.gt?`${e.gt} < n `:`${e.gte} <= n `}${"number"==typeof e.lt?`< ${e.lt}`:`<= ${e.lte}`}`}(e);return[r,n,t,i].filter(e=>!!e).join(" ")}(n)}, got ${g(e)}.`,c(e,t))}const h=new WeakSet,p=new WeakSet,m=new WeakSet,f=new WeakSet,y=new WeakSet;function b(e,t){if(!function(e){return!(!Array.isArray(e)||!p.has(e)&&(m.has(e)||(e.every(e=>d(e))?(h.add(e),p.add(e),0):(m.add(e),1))))}(e))throw new r(`Expected a vector, but got ${e}`,t)}function v(e,t){if(!function(e){if(!Array.isArray(e))return!1;if(f.has(e))return!0;if(y.has(e))return!1;if(0===e.length)return y.add(e),!1;if(!Array.isArray(e[0]))return y.add(e),!1;const r=e[0].length;for(const t of e.slice(1)){if(!Array.isArray(t))return y.add(e),!1;if(t.length!==r)return y.add(e),!1}return h.add(e),f.add(e),!0}(e))throw new r(`Expected a grid, but got ${e}`,t)}function w(e,t,n){return new r(`Expected ${e}, got ${g(t)}.`,c(t,n))}function A(e,r){if(!Array.isArray(e))throw w("array",e,r)}function N(e){return null!==e&&"object"==typeof e&&!!e[o]}function x(e,r){return $(e,r),e}function $(e,r){if(!function(e){return void 0!==e}(e))throw w("not undefined",e,r)}function T(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof RegExp||N(e)||(r=e,null!==r&&"object"==typeof r&&r[s]));var r}function K(e){return function(e){return Array.isArray(e)||"string"==typeof e}(e)||T(e)}function C(e,r){if(!function(e){return"number"==typeof e||!!K(e)||!!N(e)}(e))throw w("FunctionLike",e,r)}function F(e){return{min:e,max:e}}function S(e,r){return e instanceof Promise?e.then(r):r(e)}function k(e,r){const t=[];for(let n=0;n<e.length;n++){const i=r(e[n],n);if(i instanceof Promise)return E(i,t,e,r,n);t.push(i)}return t}async function E(e,r,t,n,i){r.push(await e);for(let e=i+1;e<t.length;e++)r.push(await n(t[e],e));return r}function O(e,r,t){let n=t;for(let t=0;t<e.length;t++){const i=r(n,e[t],t);if(i instanceof Promise)return P(i,e,r,t);n=i}return n}async function P(e,r,t,n){let i=await e;for(let e=n+1;e<r.length;e++)i=await t(i,r[e],e);return i}function R(e,r){for(let t=0;t<e.length;t++){const n=r(e[t],t);if(n instanceof Promise)return j(n,e,r,t);if(n)return!0}return!1}async function j(e,r,t,n){if(await e)return!0;for(let e=n+1;e<r.length;e++)if(await t(r[e],e))return!0;return!1}function U(e,r){for(let t=0;t<e.length;t++){const n=r(e[t],t);if(n instanceof Promise)return z(n,e,r,t);if(!n)return!1}return!0}async function z(e,r,t,n){if(!await e)return!1;for(let e=n+1;e<r.length;e++)if(!await t(r[e],e))return!1;return!0}const I={"every?":{category:"grid",description:"Checks if all elements in a grid satisfy a predicate. Returns true only if the predicate returns true for every element in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['// Using "as" alias because "every?" shadows a builtin function\nlet { every? as grid-every? } = import("grid");\ngrid-every?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], string?)','// Using "as" alias because "every?" shadows a builtin function\nlet { every? as grid-every? } = import("grid");\ngrid-every?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], string?)','// Using "as" alias because "every?" shadows a builtin function\nlet { every? as grid-every? } = import("grid");\ngrid-every?([\n [1, 2],\n [3, 4],\n], string?)'],seeAlso:["collection.every?","grid.some?","grid.every-row?","grid.every-col?"]},"some?":{category:"grid",description:"Checks if any element in a grid satisfies a predicate. Returns true if the predicate returns true for at least one element in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some? } = import("grid");\nsome?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], string?)','let { some? } = import("grid");\nsome?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], string?)','let { some? } = import("grid");\nsome?([\n [1, 2],\n [3, 4],\n], string?)'],seeAlso:["collection.any?","grid.every?","grid.some-row?","grid.some-col?"]},"every-row?":{category:"grid",description:"Checks if all rows in a grid satisfy a predicate. Returns true only if the predicate returns true for every row in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { every-row? } = import("grid");\nevery-row?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> string?($[0]))','let { every-row? } = import("grid");\nevery-row?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> string?($[0]))','let { every-row? } = import("grid");\nevery-row?([\n [1, 2],\n [3, 4],\n], -> string?($[0]))'],seeAlso:["grid.some-row?","grid.every-col?","grid.every?"]},"some-row?":{category:"grid",description:"Checks if any row in a grid satisfies a predicate. Returns true if the predicate returns true for at least one row in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some-row? } = import("grid");\nsome-row?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $ contains? "Albert")','let { some-row? } = import("grid");\nsome-row?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> $ contains? "Albert")','let { some-row? } = import("grid");\nsome-row?([\n [1, 2],\n [3, 4],\n], -> $ contains? "Albert")'],seeAlso:["grid.every-row?","grid.some-col?","grid.some?"]},"every-col?":{category:"grid",description:"Checks if all columns in a grid satisfy a predicate. Returns true only if the predicate returns true for every column in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { every-col? } = import("grid");\nevery-col?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> string?($[0]))','let { every-col? } = import("grid");\nevery-col?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> string?($[0]))','let { every-col? } = import("grid");\nevery-col?([\n [1, 2],\n [3, 4],\n], -> string?($[0]))'],seeAlso:["grid.some-col?","grid.every-row?","grid.every?"]},"some-col?":{category:"grid",description:"Checks if any column in a grid satisfies a predicate. Returns true if the predicate returns true for at least one column in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some-col? } = import("grid");\nsome-col?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $ contains? "Albert")','let { some-col? } = import("grid");\nsome-col?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> $ contains? "Albert")','let { some-col? } = import("grid");\nsome-col?([\n [1, 2],\n [3, 4],\n], -> $ contains? "Albert")'],seeAlso:["grid.every-col?","grid.some-row?","grid.some?"]},row:{category:"grid",description:"Returns the row at index $a in the grid $b.",returns:{type:"any"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { row } = import("grid");\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 0)','let { row } = import("grid");\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)','let { row } = import("grid");\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 2)'],seeAlso:["grid.col","grid.shape"]},col:{category:"grid",description:"Returns the column at index $a in the grid $b.",returns:{type:"any"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { col } = import("grid");\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 0)','let { col } = import("grid");\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)','let { col } = import("grid");\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 2)'],seeAlso:["grid.row","grid.shape"]},shape:{category:"grid",description:"Returns the shape of the grid `g` as a `vector` of two numbers, where the first number is the number of rows and the second number is the number of columns.",returns:{type:"vector"},args:{g:{type:"grid",description:"The grid to get the shape of."}},variants:[{argumentNames:["g"]}],examples:['let { shape } = import("grid");\nshape([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { shape } = import("grid");\nshape([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])','let { shape } = import("grid");\nshape([\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.row","grid.col","grid.reshape"]},fill:{category:"grid",description:"Creates a grid of the specified size, filled with the specified value.",returns:{type:"grid"},args:{rows:{type:"integer",description:"The number of rows in the grid."},cols:{type:"integer",description:"The number of columns in the grid."},value:{type:"any",description:"The value to fill the grid with."}},variants:[{argumentNames:["rows","cols","value"]}],examples:['let { fill } = import("grid");\nfill(2, 3, 0)','let { fill } = import("grid");\nfill(2, 3, "x")'],seeAlso:["grid.generate","grid.from-array","vector.fill"]},generate:{category:"grid",description:"Generates a grid of the specified size, where each element is generated by the provided function.",returns:{type:"grid"},args:{rows:{type:"number",description:"The number of rows in the grid."},cols:{type:"number",description:"The number of columns in the grid."},fn:{type:"function",description:"The function to generate the grid. It takes two arguments: the row index and the column index."}},variants:[{argumentNames:["rows","cols","fn"]}],examples:['let { generate } = import("grid");\ngenerate(3, 3, (i, j) -> i + j)'],seeAlso:["grid.fill","grid.from-array","vector.generate"]},reshape:{category:"grid",description:"Reshapes the grid `a` into a new grid with the specified number of rows `b`. The number of columns is automatically calculated based on the total number of elements in the grid.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { reshape } = import("grid");\nreshape([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], 2)'],seeAlso:["grid.shape","grid.from-array"]},transpose:{category:"grid",description:"Transposes the grid `g`, swapping its rows and columns.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to transpose."}},variants:[{argumentNames:["g"]}],examples:['let { transpose } = import("grid");\ntranspose([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { transpose } = import("grid");\ntranspose([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])','let { transpose } = import("grid");\ntranspose([\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.flip-h","grid.flip-v","grid.rotate"]},"flip-h":{category:"grid",description:"Flips the grid `g` horizontally.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to flip horizontally."}},variants:[{argumentNames:["g"]}],examples:['let { flip-h } = import("grid");\nflip-h([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { flip-h } = import("grid");\nflip-h([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])','let { flip-h } = import("grid");\nflip-h([\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.flip-v","grid.transpose","grid.rotate","grid.reverse-cols"]},"flip-v":{category:"grid",description:"Flips the grid `g` vertically.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to flip vertically."}},variants:[{argumentNames:["g"]}],examples:['let { flip-v } = import("grid");\nflip-v([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { flip-v } = import("grid");\nflip-v([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])','let { flip-v } = import("grid");\nflip-v([\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.flip-h","grid.transpose","grid.rotate","grid.reverse-rows"]},rotate:{category:"grid",description:"Rotates the grid `g` by the specified angle. The angle is given in terms of 90-degree rotations. Positive values rotate the grid clockwise, while negative values rotate it counterclockwise.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:['let { rotate } = import("grid");\nrotate([\n [1, 2],\n [3, 4],\n], 1)','let { rotate } = import("grid");\nrotate([\n [1, 2],\n [3, 4],\n], 2)','let { rotate } = import("grid");\nrotate([\n [1, 2],\n [3, 4],\n], 3)','let { rotate } = import("grid");\nrotate([\n [1, 2],\n [3, 4],\n], 4)','let { rotate } = import("grid");\nrotate([\n [1, 2],\n [3, 4],\n], -1)','let { rotate } = import("grid");\nrotate([\n [1, 2],\n [3, 4],\n], -2)','let { rotate } = import("grid");\nrotate([\n [1, 2],\n [3, 4],\n], -3)'],seeAlso:["grid.transpose","grid.flip-h","grid.flip-v"]},"reverse-rows":{category:"grid",description:"Reverses the order of rows in the grid `g`.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to reverse rows."}},variants:[{argumentNames:["g"]}],examples:['let { reverse-rows } = import("grid");\nreverse-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { reverse-rows } = import("grid");\nreverse-rows([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])','let { reverse-rows } = import("grid");\nreverse-rows([\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.reverse-cols","grid.flip-v"]},"reverse-cols":{category:"grid",description:"Reverses the order of columns in the grid `g`.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to reverse columns."}},variants:[{argumentNames:["g"]}],examples:['let { reverse-cols } = import("grid");\nreverse-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { reverse-cols } = import("grid");\nreverse-cols([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])','let { reverse-cols } = import("grid");\nreverse-cols([\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.reverse-rows","grid.flip-h"]},slice:{category:"grid",description:"Slices the grid `g` from the starting index `begin` to the optional ending index `stop`. The slice is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"vector",description:"The starting index of the slice as a vector of two numbers: `[row, col]`."},stop:{type:"vector",description:"Optional ending index of the slice as a vector of two numbers: `[row, col]`."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['// Using "as" alias because "slice" shadows a builtin function\nlet { slice as grid-slice } = import("grid");\ngrid-slice([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [1, 1], [2, 2])','// Using "as" alias because "slice" shadows a builtin function\nlet { slice as grid-slice } = import("grid");\ngrid-slice([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [1, 1])'],hideOperatorForm:!0,seeAlso:["grid.slice-rows","grid.slice-cols"]},"slice-rows":{category:"grid",description:"Slices rows of the grid `g` from the starting index `begin` to the optional ending index `stop`. The slice is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"number",description:"The starting index of the slice."},stop:{type:"number",description:"Optional ending index of the slice."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['let { slice-rows } = import("grid");\nslice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { slice-rows } = import("grid");\nslice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)'],hideOperatorForm:!0,seeAlso:["grid.slice","grid.slice-cols","grid.splice-rows"]},"slice-cols":{category:"grid",description:"Slices columns of the grid `g` from the starting index `begin` to the optional ending index `stop`. The slice is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"number",description:"The starting index of the slice."},stop:{type:"number",description:"Optional ending index of the slice."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['let { slice-cols } = import("grid");\nslice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { slice-cols } = import("grid");\nslice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)'],hideOperatorForm:!0,seeAlso:["grid.slice","grid.slice-rows","grid.splice-cols"]},"splice-rows":{category:"grid",description:"Splices rows of the grid `g` starting from the index `begin`. Deletes `deleteCount` rows and inserts the specified `items` at that position.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to splice."},begin:{type:"number",description:"The starting index of the splice."},deleteCount:{type:"number",description:"The number of rows to delete."},items:{type:"array",rest:!0,description:"The rows to insert."}},variants:[{argumentNames:["g","begin","deleteCount"]},{argumentNames:["g","begin","deleteCount","items"]}],examples:['let { splice-rows } = import("grid");\nsplice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { splice-rows } = import("grid");\nsplice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 1, ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.splice-cols","grid.slice-rows"]},"splice-cols":{category:"grid",description:"Splices columns of the grid `g` starting from the index `begin`. Deletes `deleteCount` columns and inserts the specified `items` at that position.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to splice."},begin:{type:"number",description:"The starting index of the splice."},deleteCount:{type:"number",description:"The number of columns to delete."},items:{type:"array",rest:!0,description:"The columns to insert."}},variants:[{argumentNames:["g","begin","deleteCount"]},{argumentNames:["g","begin","deleteCount","items"]}],examples:['let { splice-cols } = import("grid");\nsplice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { splice-cols } = import("grid");\nsplice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 1, ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.splice-rows","grid.slice-cols"]},"concat-rows":{category:"grid",description:"Concatenates two grids `a` and `b` by rows. The number of columns in both grids must be the same.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"grid"}},variants:[{argumentNames:["a","b"]}],examples:['let { concat-rows } = import("grid");\nconcat-rows([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], [\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.concat-cols","grid.push-rows"]},"concat-cols":{category:"grid",description:"Concatenates two grids `a` and `b` by columns. The number of rows in both grids must be the same.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"grid"}},variants:[{argumentNames:["a","b"]}],examples:['let { concat-cols } = import("grid");\nconcat-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])'],seeAlso:["grid.concat-rows","grid.push-cols"]},map:{category:"grid",description:"Maps a function `a` over each element of the grid `b`, returning a new grid with the results.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['// Using "as" alias because "map" shadows a builtin function\nlet { map as grid-map } = import("grid");\ngrid-map([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], str)'],seeAlso:["map","grid.mapi","grid.reduce"]},mapi:{category:"grid",description:"Maps a function `a` over each element of the grid `b`, passing the row and column index as additional arguments to the function.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['// Using "as" alias because "mapi" shadows a builtin function\nlet { mapi as grid-mapi } = import("grid");\ngrid-mapi([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $1 ++ "(" ++ $2 ++ ", " ++ $3 ++ ")")'],seeAlso:["grid.map","grid.reducei","map"]},reduce:{category:"grid",description:"Reduces the grid `a` using the function `b`, returning a single value.",returns:{type:"any"},args:{g:{type:"grid",description:"The grid to reduce."},fn:{type:"function",description:"The function to reduce the grid. It takes two arguments: the accumulator and the current element."},"initial-value":{type:"any",description:"The initial value for the accumulator."}},variants:[{argumentNames:["g","fn","initial-value"]}],examples:['// Using "as" alias because "reduce" shadows a builtin function\nlet { reduce as grid-reduce } = import("grid");\ngrid-reduce([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ++, "")'],seeAlso:["reduce","grid.reducei","grid.map"]},reducei:{category:"grid",description:"Reduces the grid `a` using the function `b`, passing the row and column indices as additional arguments to the function.",returns:{type:"any"},args:{g:{type:"grid",description:"The grid to reduce."},fn:{type:"function",description:"The function to reduce the grid. It takes four arguments: the accumulator, the current element, the row index, and the column index."},"initial-value":{type:"any",description:"The initial value for the accumulator."}},variants:[{argumentNames:["g","fn","initial-value"]}],examples:['// Using "as" alias because "reducei" shadows a builtin function\nlet { reducei as grid-reducei } = import("grid");\ngrid-reducei([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ++, "")'],seeAlso:["grid.reduce","grid.mapi","reduce"]},"push-rows":{category:"grid",description:"Pushes the specified rows into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to push rows into."},rows:{type:"array",rest:!0,description:"The rows to push into the grid."}},variants:[{argumentNames:["g","rows"]}],examples:['let { push-rows } = import("grid");\npush-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.unshift-rows","grid.pop-row","grid.shift-row","grid.concat-rows"]},"unshift-rows":{category:"grid",description:"Unshifts the specified rows into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to unshift rows into."},rows:{type:"array",rest:!0,description:"The rows to unshift into the grid."}},variants:[{argumentNames:["g","rows"]}],examples:['let { unshift-rows } = import("grid");\nunshift-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.push-rows","grid.shift-row","grid.pop-row"]},"pop-row":{category:"grid",description:"Pops the last row from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to pop a row from."}},variants:[{argumentNames:["g"]}],examples:['let { pop-row } = import("grid");\npop-row([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.shift-row","grid.push-rows","grid.unshift-rows"]},"shift-row":{category:"grid",description:"Shifts the first row from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to shift a row from."}},variants:[{argumentNames:["g"]}],examples:['let { shift-row } = import("grid");\nshift-row([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.pop-row","grid.push-rows","grid.unshift-rows"]},"push-cols":{category:"grid",description:"Pushes the specified columns into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to push columns into."},cols:{type:"array",rest:!0,description:"The columns to push into the grid."}},variants:[{argumentNames:["g","cols"]}],examples:['let { push-cols } = import("grid");\npush-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.unshift-cols","grid.pop-col","grid.shift-col","grid.concat-cols"]},"unshift-cols":{category:"grid",description:"Unshifts the specified columns into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to unshift columns into."},cols:{type:"array",rest:!0,description:"The columns to unshift into the grid."}},variants:[{argumentNames:["g","cols"]}],examples:['let { unshift-cols } = import("grid");\nunshift-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.push-cols","grid.shift-col","grid.pop-col"]},"pop-col":{category:"grid",description:"Pops the last column from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to pop a column from."}},variants:[{argumentNames:["g"]}],examples:['let { pop-col } = import("grid");\npop-col([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.shift-col","grid.push-cols","grid.unshift-cols"]},"shift-col":{category:"grid",description:"Shifts the first column from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to shift a column from."}},variants:[{argumentNames:["g"]}],examples:['let { shift-col } = import("grid");\nshift-col([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.pop-col","grid.push-cols","grid.unshift-cols"]},"from-array":{category:"grid",description:"Creates a grid from a flat array with specified dimensions. The array is reshaped into the specified number of rows, and the number of columns is automatically calculated based on the total number of elements in the array.",returns:{type:"grid"},args:{a:{type:"array"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { from-array } = import("grid");\nfrom-array([1, 2, 3, 4], 2)','let { from-array } = import("grid");\nfrom-array([1, 2, 3, 4], 4)'],seeAlso:["grid.fill","grid.generate","grid.reshape"]}};function M(e){const r=[];for(let t=0;t<e[0].length;t+=1){const n=[];for(let r=0;r<e.length;r+=1)n.push(e[r][t]);r.push(n)}return r}const B={"every?":{evaluate:([e,r],t,n,{executeFunction:i})=>{v(e,t),C(r,t);const o=[];for(const r of e)for(const e of r)o.push(e);return U(o,e=>i(r,[e],n,t))},arity:F(2)},"some?":{evaluate:([e,r],t,n,{executeFunction:i})=>{v(e,t),C(r,t);const o=[];for(const r of e)for(const e of r)o.push(e);return R(o,e=>i(r,[e],n,t))},arity:F(2)},"every-row?":{evaluate:([e,r],t,n,{executeFunction:i})=>(v(e,t),C(r,t),U(Array.from(e),e=>i(r,[e],n,t))),arity:F(2)},"some-row?":{evaluate:([e,r],t,n,{executeFunction:i})=>(v(e,t),C(r,t),R(Array.from(e),e=>i(r,[e],n,t))),arity:F(2)},"every-col?":{evaluate:([e,r],t,n,{executeFunction:i})=>{v(e,t),C(r,t);const o=M(e);return U(Array.from(o),e=>i(r,[e],n,t))},arity:F(2)},"some-col?":{evaluate:([e,r],t,n,{executeFunction:i})=>{v(e,t),C(r,t);const o=M(e);return R(Array.from(o),e=>i(r,[e],n,t))},arity:F(2)},row:{evaluate:([e,r],t)=>(v(e,t),u(r,t,{integer:!0,nonNegative:!0,lt:e.length}),e[r]),arity:F(2)},col:{evaluate:([e,r],t)=>(v(e,t),u(r,t,{integer:!0,nonNegative:!0,lt:e[0].length}),e.map(e=>e[r])),arity:F(2)},shape:{evaluate:([e],r)=>(v(e,r),[e.length,e[0].length]),arity:F(1)},fill:{evaluate:([e,r,t],n)=>{u(e,n,{integer:!0,positive:!0}),u(r,n,{integer:!0,positive:!0}),$(t,n);const i=[];for(let n=0;n<e;n+=1){const e=[];for(let n=0;n<r;n+=1)e.push(t);i.push(e)}return i},arity:F(3)},generate:{evaluate:([e,r,t],n,i,{executeFunction:o})=>(u(e,n,{integer:!0,positive:!0}),u(r,n,{integer:!0,positive:!0}),C(t,n),k(Array.from({length:e}),(e,s)=>k(Array.from({length:r}),(e,r)=>S(o(t,[s,r],i,n),e=>($(e,n),e))))),arity:F(3)},reshape:{evaluate:([e,t],n)=>{v(e,n),u(t,n,{integer:!0,positive:!0});const i=e.flat();if(i.length%t!==0)throw new r(`The number of elements in the grid must be divisible by rows, but got ${i.length} and ${t}`,n);const o=i.length/t,s=[];for(let e=0;e<t;e+=1){const r=[];for(let t=0;t<o;t+=1)r.push(i[e*o+t]);s.push(r)}return s},arity:F(2)},transpose:{evaluate:([e],r)=>(v(e,r),M(e)),arity:F(1)},"flip-h":{evaluate:([e],r)=>(v(e,r),e.map(e=>e.reverse())),arity:F(1)},"flip-v":{evaluate:([e],r)=>(v(e,r),e.reverse()),arity:F(1)},rotate:{evaluate:([e,r],t)=>{if(v(e,t),u(r,t,{integer:!0}),0===(r=(r%4+4)%4)||0===e.length)return e.map(e=>[...e]);const n=e.length,i=e[0].length;let o;switch(r){case 1:o=Array(i).fill(null).map(()=>Array(n).fill(null));for(let r=0;r<n;r++)for(let t=0;t<i;t++)o[t][n-1-r]=e[r][t];break;case 2:o=Array(n).fill(null).map(()=>Array(i).fill(null));for(let r=0;r<n;r++)for(let t=0;t<i;t++)o[n-1-r][i-1-t]=e[r][t];break;case 3:o=Array(i).fill(null).map(()=>Array(n).fill(null));for(let r=0;r<n;r++)for(let t=0;t<i;t++)o[i-1-t][r]=e[r][t]}return o},arity:F(2)},"reverse-rows":{evaluate:([e],r)=>(v(e,r),e.reverse()),arity:F(1)},"reverse-cols":{evaluate:([e],r)=>(v(e,r),e.map(e=>e.reverse())),arity:F(1)},slice:{evaluate:([e,t,n],i)=>{if(v(e,i),b(t,i),2!==t.length)throw new r(`The start vector must have 2 elements, but got ${t.length}`,i);const[o,s]=t;if(u(o,i,{integer:!0,nonNegative:!0,lt:e.length}),u(s,i,{integer:!0,nonNegative:!0,lt:e[0].length}),n??=[e.length,e[0].length],b(n,i),2!==n.length)throw new r(`The end vector must have 2 elements, but got ${n.length}`,i);const[a,l]=n;u(a,i,{gt:o,lte:e.length}),u(l,i,{gt:s,lte:e[0].length});const g=[];for(let r=o;r<a;r+=1){const t=[];for(let n=s;n<l;n+=1)t.push(e[r][n]);g.push(t)}return g},arity:{min:2,max:3}},"slice-rows":{evaluate:([e,r,t],n)=>(v(e,n),void 0===t?(u(r,n,{integer:!0,lte:e.length,gte:-e.length}),r<0?e.slice(e.length+r):e.slice(r)):(u(r,n,{integer:!0,nonNegative:!0,lte:e.length}),u(t,n,{integer:!0}),u(t=t<0?e.length+t:t,n,{gt:r,lte:e.length}),e.slice(r,t))),arity:{min:2,max:3}},"slice-cols":{evaluate:([e,r,t],n)=>{v(e,n);const i=M(e);return void 0===t?(u(r,n,{integer:!0,lte:i.length,gte:-i.length}),M(r<0?i.slice(i.length+r):i.slice(r))):(u(r,n,{integer:!0,nonNegative:!0,lte:i.length}),u(t,n,{integer:!0}),u(t=t<0?i.length+t:t,n,{gt:r,lte:i.length}),M(i.slice(r,t)))},arity:{min:2,max:3}},"splice-rows":{evaluate:([e,t,n,...i],o)=>{v(e,o),u(t,o,{integer:!0,nonNegative:!0,lte:e.length}),u(n,o,{integer:!0,nonNegative:!0}),0!==i.length&&(v(i,o),i.every(t=>{if(A(t,o),e[0].length!==t.length)throw new r(`All rows must have the same length as the number of columns in grid, but got ${t.length}`,o);return!0}));const s=[];for(let r=0;r<t;r+=1)s.push(e[r]);i.length>0&&s.push(...i);for(let r=t+n;r<e.length;r+=1)s.push(e[r]);return s},arity:{min:3}},"splice-cols":{evaluate:([e,t,n,...i],o)=>{v(e,o);const s=M(e);u(t,o,{integer:!0,nonNegative:!0,lte:s.length}),u(n,o,{integer:!0,nonNegative:!0}),0!==i.length&&(v(i,o),i.every(e=>{if(A(e,o),s[0].length!==e.length)throw new r(`All rows must have the same length as the number of rows in grid, but got ${e.length}`,o);return!0}));const a=[];for(let e=0;e<t;e+=1)a.push(s[e]);a.push(...i);for(let e=t+n;e<s.length;e+=1)a.push(s[e]);return M(a)},arity:{min:3}},"concat-rows":{evaluate:(e,t)=>{A(e,t),e.every(e=>v(e,t));const n=e[0][0].length;e.slice(1).every(e=>{if(e[0].length!==n)throw new r(`All grids must have the same number of columns, but got ${n} and ${e[0].length}`,t);return!0});const i=[];return e.forEach(e=>{e.forEach(e=>{i.push(e)})}),i},arity:{min:1}},"concat-cols":{evaluate:(e,t)=>{A(e,t),e.every(e=>v(e,t));const n=e[0].length;e.slice(1).every(e=>{if(e.length!==n)throw new r(`All grids must have the same number of rows, but got ${n} and ${e.length}`,t);return!0});const i=[];for(let r=0;r<n;r+=1){const t=[];e.forEach(e=>{t.push(...e[r])}),i.push(t)}return i},arity:{min:1}},map:{evaluate:(e,t,n,{executeFunction:i})=>{const o=function(e,r){return C(e,r),e}(e.at(-1),t),s=e.slice(0,-1);v(s[0],t);const a=s[0].length,l=s[0][0].length;return s.slice(1).forEach(e=>{if(v(e,t),e.length!==a)throw new r(`All grids must have the same number of rows, but got ${a} and ${e.length}`,t);if(e[0].length!==l)throw new r(`All grids must have the same number of columns, but got ${l} and ${e[0].length}`,t)}),k(Array.from({length:a}),(e,r)=>k(Array.from({length:l}),(e,a)=>{const l=s.map(e=>e[r][a]);return S(i(o,l,n,t),e=>x(e))}))},arity:{min:2}},mapi:{evaluate:([e,r],t,n,{executeFunction:i})=>{v(e,t),C(r,t);const o=e.length,s=e[0].length;return k(Array.from({length:o}),(o,a)=>k(Array.from({length:s}),(o,s)=>S(i(r,[e[a][s],a,s],n,t),e=>x(e))))},arity:F(2)},reduce:{evaluate:([e,r,t],n,i,{executeFunction:o})=>{v(e,n),C(r,n);const s=[];for(const r of e)for(const e of r)s.push(e);return O(s,(e,t)=>o(r,[e,t],i,n),x(t))},arity:F(3)},reducei:{evaluate:([e,r,t],n,i,{executeFunction:o})=>{v(e,n),C(r,n);const s=[];for(let r=0;r<e.length;r+=1)for(let t=0;t<e[r].length;t+=1)s.push({cell:e[r][t],i:r,j:t});return O(s,(e,{cell:t,i:s,j:a})=>o(r,[e,t,s,a],i,n),x(t))},arity:F(3)},"push-rows":{evaluate:([e,...t],n)=>{if(v(e,n),v(t,n),e[0].length!==t[0].length)throw new r(`All rows must have the same length as the number of columns in grid, but got ${e[0].length} and ${t[0].length}`,n);return[...e,...t]},arity:{min:2}},"unshift-rows":{evaluate:([e,...t],n)=>{if(v(e,n),v(t,n),e[0].length!==t[0].length)throw new r(`All rows must have the same length as the number of columns in grid, but got ${e[0].length} and ${t[0].length}`,n);return[...t,...e]},arity:{min:2}},"pop-row":{evaluate:([e],r)=>(v(e,r),1===e.length?null:e.slice(0,-1)),arity:F(1)},"shift-row":{evaluate:([e],r)=>(v(e,r),1===e.length?null:e.slice(1)),arity:F(1)},"push-cols":{evaluate:([e,...t],n)=>{if(v(e,n),v(t,n),e.length!==t[0].length)throw new r(`All columns must have the same length as the number of rows in grid, but got ${t.length}`,n);const i=[];for(let r=0;r<e.length;r+=1){const n=[];n.push(...e[r]),t.forEach(e=>{n.push(e[r])}),i.push(n)}return i},arity:{min:2}},"unshift-cols":{evaluate:([e,...t],n)=>{if(v(e,n),v(t,n),e.length!==t[0].length)throw new r(`All columns must have the same length as the number of rows in grid, but got ${t.length}`,n);const i=[];for(let r=0;r<e.length;r+=1){const n=[];t.forEach(e=>{n.push(e[r])}),n.push(...e[r]),i.push(n)}return i},arity:{min:2}},"pop-col":{evaluate:([e],r)=>(v(e,r),1===e[0].length?null:e.map(e=>e.slice(0,-1))),arity:F(1)},"shift-col":{evaluate:([e],r)=>(v(e,r),1===e[0].length?null:e.map(e=>e.slice(1))),arity:F(1)},"from-array":{evaluate:([e,t],n)=>{if(A(e,n),u(t,n,{integer:!0,positive:!0}),e.length%t!==0)throw new r(`The number of elements in the array must be divisible by rows, but got ${e.length} and ${t}`,n);return function(e,r){const t=[],n=e.length/r;for(let i=0;i<r;i++){const r=i*n,o=r+n;t.push(e.slice(r,o))}return t}(e,t)},arity:F(2)}};for(const[e,r]of Object.entries(I))B[e]&&(B[e].docs=r);const W={name:"grid",functions:B};export{W as gridModule};
|
|
2
2
|
//# sourceMappingURL=grid.esm.js.map
|