@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.
Files changed (65) hide show
  1. package/README.md +1 -0
  2. package/dist/cli/cli.js +1264 -909
  3. package/dist/cli/src/Lits/Lits.d.ts +8 -2
  4. package/dist/cli/src/builtin/bindingNode.d.ts +2 -1
  5. package/dist/cli/src/builtin/interface.d.ts +3 -2
  6. package/dist/cli/src/builtin/modules/number-theory/sequences/index.d.ts +2 -1
  7. package/dist/cli/src/evaluator/functionExecutors.d.ts +2 -1
  8. package/dist/cli/src/evaluator/index.d.ts +3 -2
  9. package/dist/cli/src/evaluator/interface.d.ts +3 -2
  10. package/dist/cli/src/utils/maybePromise.d.ts +54 -0
  11. package/dist/full.esm.js +1 -1
  12. package/dist/full.esm.js.map +1 -1
  13. package/dist/full.js +1 -1
  14. package/dist/full.js.map +1 -1
  15. package/dist/index.esm.js +1 -1
  16. package/dist/index.esm.js.map +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/lits.iife.js +1 -1
  20. package/dist/lits.iife.js.map +1 -1
  21. package/dist/modules/assert.esm.js +1 -1
  22. package/dist/modules/assert.esm.js.map +1 -1
  23. package/dist/modules/assert.js +1 -1
  24. package/dist/modules/assert.js.map +1 -1
  25. package/dist/modules/collection.esm.js +1 -1
  26. package/dist/modules/collection.esm.js.map +1 -1
  27. package/dist/modules/collection.js +1 -1
  28. package/dist/modules/collection.js.map +1 -1
  29. package/dist/modules/grid.esm.js +1 -1
  30. package/dist/modules/grid.esm.js.map +1 -1
  31. package/dist/modules/grid.js +1 -1
  32. package/dist/modules/grid.js.map +1 -1
  33. package/dist/modules/number-theory.esm.js +1 -1
  34. package/dist/modules/number-theory.esm.js.map +1 -1
  35. package/dist/modules/number-theory.js +1 -1
  36. package/dist/modules/number-theory.js.map +1 -1
  37. package/dist/modules/sequence.esm.js +1 -1
  38. package/dist/modules/sequence.esm.js.map +1 -1
  39. package/dist/modules/sequence.js +1 -1
  40. package/dist/modules/sequence.js.map +1 -1
  41. package/dist/modules/src/Lits/Lits.d.ts +8 -2
  42. package/dist/modules/src/builtin/bindingNode.d.ts +2 -1
  43. package/dist/modules/src/builtin/interface.d.ts +3 -2
  44. package/dist/modules/src/builtin/modules/number-theory/sequences/index.d.ts +2 -1
  45. package/dist/modules/src/evaluator/functionExecutors.d.ts +2 -1
  46. package/dist/modules/src/evaluator/index.d.ts +3 -2
  47. package/dist/modules/src/evaluator/interface.d.ts +3 -2
  48. package/dist/modules/src/utils/maybePromise.d.ts +54 -0
  49. package/dist/modules/vector.esm.js +1 -1
  50. package/dist/modules/vector.esm.js.map +1 -1
  51. package/dist/modules/vector.js +1 -1
  52. package/dist/modules/vector.js.map +1 -1
  53. package/dist/src/Lits/Lits.d.ts +8 -2
  54. package/dist/src/builtin/bindingNode.d.ts +2 -1
  55. package/dist/src/builtin/interface.d.ts +3 -2
  56. package/dist/src/builtin/modules/number-theory/sequences/index.d.ts +2 -1
  57. package/dist/src/evaluator/functionExecutors.d.ts +2 -1
  58. package/dist/src/evaluator/index.d.ts +3 -2
  59. package/dist/src/evaluator/interface.d.ts +3 -2
  60. package/dist/src/utils/maybePromise.d.ts +54 -0
  61. package/dist/testFramework.esm.js +1 -1
  62. package/dist/testFramework.esm.js.map +1 -1
  63. package/dist/testFramework.js +1 -1
  64. package/dist/testFramework.js.map +1 -1
  65. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"grid.esm.js","sources":["../../src/utils/debug/getCodeMarker.ts","../../src/errors.ts","../../src/constants/constants.ts","../../src/utils/symbols.ts","../../src/utils/debug/debugTools.ts","../../src/utils/debug/getSourceCodeInfo.ts","../../src/typeGuards/number.ts","../../src/typeGuards/annotatedArrays.ts","../../src/utils/getAssertionError.ts","../../src/typeGuards/array.ts","../../src/typeGuards/litsFunction.ts","../../src/typeGuards/lits.ts","../../src/utils/arity.ts","../../src/builtin/modules/grid/docs.ts","../../src/builtin/modules/grid/transpose.ts","../../src/builtin/modules/grid/index.ts","../../src/builtin/modules/grid/fromArray.ts"],"sourcesContent":["import type { SourceCodeInfo } from '../../tokenizer/token'\n\nexport function getCodeMarker(sourceCodeInfo: SourceCodeInfo): string {\n if (!sourceCodeInfo.position || !sourceCodeInfo.code)\n return ''\n\n const leftPadding = sourceCodeInfo.position.column - 1\n const rightPadding = sourceCodeInfo.code.length - leftPadding - 1\n return `${' '.repeat(Math.max(leftPadding, 0))}^${' '.repeat(Math.max(rightPadding, 0))}`\n}\n","import { getCodeMarker } from '../src/utils/debug/getCodeMarker'\nimport type { Arr } from './interface'\nimport type { SourceCodeInfo } from './tokenizer/token'\n\nfunction getLitsErrorMessage(message: string, sourceCodeInfo?: SourceCodeInfo) {\n if (!sourceCodeInfo) {\n return message\n }\n const location = `${sourceCodeInfo.position.line}:${sourceCodeInfo.position.column}`\n const filePathLine = sourceCodeInfo.filePath\n ? `\\n${sourceCodeInfo.filePath}:${location}`\n : `\\nLocation ${location}`\n const codeLine = `\\n${sourceCodeInfo.code}`\n const codeMarker = `\\n${getCodeMarker(sourceCodeInfo)}`\n return `${message}${filePathLine}${codeLine}${codeMarker}`\n}\n\nexport class RecurSignal extends Error {\n public params: Arr\n constructor(params: Arr) {\n super(`recur, params: ${params}`)\n Object.setPrototypeOf(this, RecurSignal.prototype)\n this.name = 'RecurSignal'\n this.params = params\n }\n}\n\nexport class LitsError extends Error {\n public readonly sourceCodeInfo?: SourceCodeInfo\n public readonly shortMessage: string\n constructor(err: unknown, sourceCodeInfo: SourceCodeInfo | undefined) {\n const message = err instanceof Error\n ? err.message\n : `${err}`\n\n super(getLitsErrorMessage(message, sourceCodeInfo))\n this.shortMessage = message\n this.sourceCodeInfo = sourceCodeInfo\n Object.setPrototypeOf(this, LitsError.prototype)\n this.name = 'LitsError'\n }\n\n public getCodeMarker(): string | undefined {\n return this.sourceCodeInfo && getCodeMarker(this.sourceCodeInfo)\n }\n}\n\nexport class UserDefinedError extends LitsError {\n public userMessage: string\n constructor(message: string, sourceCodeInfo?: SourceCodeInfo) {\n super(message, sourceCodeInfo)\n this.userMessage = message\n Object.setPrototypeOf(this, UserDefinedError.prototype)\n this.name = 'UserDefinedError'\n }\n}\n\nexport class AssertionError extends LitsError {\n constructor(message: string | Error, sourceCodeInfo?: SourceCodeInfo) {\n super(message, sourceCodeInfo)\n Object.setPrototypeOf(this, AssertionError.prototype)\n this.name = 'AssertionError'\n }\n}\n\nexport class UndefinedSymbolError extends LitsError {\n public symbol: string\n constructor(symbolName: string, sourceCodeInfo?: SourceCodeInfo) {\n const message = `Undefined symbol '${symbolName}'.`\n super(message, sourceCodeInfo)\n this.symbol = symbolName\n Object.setPrototypeOf(this, UndefinedSymbolError.prototype)\n this.name = 'UndefinedSymbolError'\n }\n}\n\nexport function isLitsError(error: unknown): error is LitsError {\n return error instanceof LitsError\n}\n","export const NodeTypes = {\n Number: 1,\n String: 2,\n NormalExpression: 3,\n SpecialExpression: 4,\n UserDefinedSymbol: 5,\n NormalBuiltinSymbol: 6,\n SpecialBuiltinSymbol: 7,\n ReservedSymbol: 8,\n Binding: 9,\n Spread: 10,\n} as const\n\nconst NodeTypesSet = new Set(Object.values(NodeTypes))\n\nexport type NodeType = typeof NodeTypes[keyof typeof NodeTypes]\n\nexport function getNodeTypeName(type: NodeType): keyof typeof NodeTypes {\n return Object.keys(NodeTypes).find(key => NodeTypes[key as keyof typeof NodeTypes] === type) as keyof typeof NodeTypes\n}\n\n// TODO, is this needed?\nexport function isNodeType(type: unknown): type is NodeType {\n return typeof type === 'number' && NodeTypesSet.has(type as NodeType)\n}\n\nconst functionTypes = [\n 'UserDefined',\n 'Partial',\n 'Comp',\n 'Constantly',\n 'Juxt',\n 'Complement',\n 'EveryPred',\n 'SomePred',\n 'Fnull',\n 'Builtin',\n 'SpecialBuiltin',\n 'NativeJsFunction',\n 'Module',\n] as const\n\nconst functionTypeSet = new Set(functionTypes)\n\nexport type FunctionType = typeof functionTypes[number]\n\nexport function isFunctionType(type: unknown): type is FunctionType {\n return typeof type === 'string' && functionTypeSet.has(type as FunctionType)\n}\n","export const FUNCTION_SYMBOL = '^^fn^^'\nexport const REGEXP_SYMBOL = '^^re^^'\n","import { getNodeTypeName, isFunctionType, isNodeType } from '../../constants/constants'\nimport type { AstNode, LitsFunction } from '../../parser/types'\nimport { FUNCTION_SYMBOL } from '../symbols'\n\nfunction isLitsFunction(func: unknown): func is LitsFunction {\n if (func === null || typeof func !== 'object')\n return false\n\n return FUNCTION_SYMBOL in func && 'functionType' in func && isFunctionType(func.functionType)\n}\n\nfunction isNode(value: unknown): value is AstNode {\n if (!Array.isArray(value) || value.length < 2)\n return false\n return isNodeType(value[0])\n}\n\nexport function valueToString(value: unknown): string {\n if (isLitsFunction(value))\n // eslint-disable-next-line ts/no-unsafe-member-access\n return `<function ${(value as any).name || '\\u03BB'}>`\n\n if (isNode(value))\n return `${getNodeTypeName(value[0])}-node`\n\n if (value === null)\n return 'null'\n\n if (typeof value === 'object' && value instanceof RegExp)\n return `${value}`\n\n if (typeof value === 'object' && value instanceof Error)\n return value.toString()\n\n return JSON.stringify(value)\n}\n","import type { SourceCodeInfo } from '../../tokenizer/token'\n\nexport function getSourceCodeInfo(anyValue: any, sourceCodeInfo: SourceCodeInfo | undefined): SourceCodeInfo | undefined {\n // eslint-disable-next-line ts/no-unsafe-return, ts/no-unsafe-member-access\n return anyValue?.sourceCodeInfo ?? sourceCodeInfo\n}\n","import { LitsError } from '../errors'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { valueToString } from '../utils/debug/debugTools'\nimport { getSourceCodeInfo } from '../utils/debug/getSourceCodeInfo'\n\ntype SignOptions =\n | {\n positive?: true\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: true\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: true\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: true\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: true\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: true\n }\n\ntype GtOptions =\n | {\n gt?: number\n gte?: never\n }\n | {\n gt?: never\n gte?: number\n }\n\ntype LtOptions =\n | {\n lt?: number\n lte?: never\n }\n | {\n lt?: never\n lte?: number\n }\n\ntype NumberOptions = {\n integer?: true\n finite?: true\n} & SignOptions &\nGtOptions &\nLtOptions\n\nfunction getRangeString(options: NumberOptions): string {\n const hasUpperAndLowerBound\n = (typeof options.gt === 'number' || typeof options.gte === 'number')\n && (typeof options.lt === 'number' || typeof options.lte === 'number')\n if (hasUpperAndLowerBound) {\n return `${typeof options.gt === 'number' ? `${options.gt} < n ` : `${options.gte} <= n `}${\n typeof options.lt === 'number' ? `< ${options.lt}` : `<= ${options.lte}`\n }`\n }\n else if (typeof options.gt === 'number' || typeof options.gte === 'number') {\n return `${typeof options.gt === 'number' ? `n > ${options.gt}` : `n >= ${options.gte}`}`\n }\n else if (typeof options.lt === 'number' || typeof options.lte === 'number') {\n return `${typeof options.lt === 'number' ? `n < ${options.lt}` : `n <= ${options.lte}`}`\n }\n else { return '' }\n}\n\nfunction getSignString(options: NumberOptions): string {\n return options.positive\n ? 'positive'\n : options.negative\n ? 'negative'\n : options.nonNegative\n ? 'non negative'\n : options.nonPositive\n ? 'non positive'\n : options.nonZero\n ? 'non zero'\n : ''\n}\n\nfunction getNumberTypeName(options: NumberOptions): string {\n if (options.zero)\n return 'zero'\n\n const sign = getSignString(options)\n const numberType = options.integer ? 'integer' : 'number'\n const finite = options.finite ? 'finite' : ''\n const range = getRangeString(options)\n\n return [sign, finite, numberType, range].filter(x => !!x).join(' ')\n}\n\nexport function isNumber(value: unknown, options: NumberOptions = {}): value is number {\n if (typeof value !== 'number')\n return false\n\n if (Number.isNaN(value))\n return false\n\n if (options.integer && !Number.isInteger(value))\n return false\n\n if (options.finite && !Number.isFinite(value))\n return false\n\n if (options.zero && value !== 0)\n return false\n\n if (options.nonZero && value === 0)\n return false\n\n if (options.positive && value <= 0)\n return false\n\n if (options.negative && value >= 0)\n return false\n\n if (options.nonPositive && value > 0)\n return false\n\n if (options.nonNegative && value < 0)\n return false\n\n if (typeof options.gt === 'number' && value <= options.gt)\n return false\n\n if (typeof options.gte === 'number' && value < options.gte)\n return false\n\n if (typeof options.lt === 'number' && value >= options.lt)\n return false\n\n if (typeof options.lte === 'number' && value > options.lte)\n return false\n\n return true\n}\n\nexport function assertNumber(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n options: NumberOptions = {},\n): asserts value is number {\n if (!isNumber(value, options)) {\n throw new LitsError(\n `Expected ${getNumberTypeName(options)}, got ${valueToString(value)}.`,\n getSourceCodeInfo(value, sourceCodeInfo),\n )\n }\n}\n\nexport function asNumber(\n value: unknown,\n sourceCodeInfo: SourceCodeInfo | undefined,\n options: NumberOptions = {},\n): number {\n assertNumber(value, sourceCodeInfo, options)\n return value\n}\n","import { LitsError } from '../errors'\nimport type { Any } from '../interface'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { isNumber } from './number'\n\nconst annotatedArrays = new WeakSet<unknown[]>()\nconst vectors = new WeakSet<unknown[]>()\nconst notVectors = new WeakSet<unknown[]>()\nconst matrices = new WeakSet<unknown[]>()\nconst notMatrices = new WeakSet<unknown[]>()\nconst grids = new WeakSet<unknown[]>()\nconst notGrids = new WeakSet<unknown[]>()\n\nexport function annotate<T>(value: T): T {\n if (!Array.isArray(value)) {\n return value\n }\n if (annotatedArrays.has(value)) {\n return value\n }\n isVector(value)\n if (!isMatrix(value)) {\n isGrid(value)\n }\n\n return value\n}\nexport function isVector(vector: unknown): vector is number[] {\n if (!Array.isArray(vector)) {\n return false\n }\n\n if (vectors.has(vector)) {\n return true\n }\n if (notVectors.has(vector)) {\n return false\n }\n\n if (vector.every(elem => isNumber(elem))) {\n annotatedArrays.add(vector)\n vectors.add(vector)\n return true\n }\n notVectors.add(vector)\n return false\n}\n\nexport function assertVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is number[] {\n if (!isVector(vector)) {\n throw new LitsError(`Expected a vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function is2dVector(vector: unknown): vector is [number, number] {\n if (!isVector(vector)) {\n return false\n }\n return vector.length === 2\n}\nexport function assert2dVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is [number, number] {\n if (!is2dVector(vector)) {\n throw new LitsError(`Expected a 2d vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function is3dVector(vector: unknown): vector is [number, number, number] {\n if (!isVector(vector)) {\n return false\n }\n return vector.length === 3\n}\nexport function assert3dVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is [number, number, number] {\n if (!is3dVector(vector)) {\n throw new LitsError(`Expected a 3d vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function assertNonEmptyVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is number[] {\n assertVector(vector, sourceCodeInfo)\n if (vector.length === 0) {\n throw new LitsError(`Expected a non empty vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function isGrid(grid: unknown): grid is unknown[][] {\n if (!Array.isArray(grid)) {\n return false\n }\n if (grids.has(grid)) {\n return true\n }\n if (notGrids.has(grid)) {\n return false\n }\n if (grid.length === 0) {\n notGrids.add(grid)\n return false\n }\n if (!Array.isArray(grid[0])) {\n notGrids.add(grid)\n return false\n }\n const nbrOfCols = grid[0].length\n for (const row of grid.slice(1)) {\n if (!Array.isArray(row)) {\n notGrids.add(grid)\n return false\n }\n if (row.length !== nbrOfCols) {\n notGrids.add(grid)\n return false\n }\n }\n annotatedArrays.add(grid)\n grids.add(grid)\n return true\n}\n\nexport function assertGrid(grid: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts grid is Any[][] {\n if (!isGrid(grid)) {\n throw new LitsError(`Expected a grid, but got ${grid}`, sourceCodeInfo)\n }\n}\n\nexport function isMatrix(matrix: unknown): matrix is number[][] {\n if (!Array.isArray(matrix)) {\n return false\n }\n if (matrices.has(matrix)) {\n return true\n }\n if (notMatrices.has(matrix)) {\n return false\n }\n if (matrix.length === 0) {\n notMatrices.add(matrix)\n return false\n }\n if (!Array.isArray(matrix[0]) || matrix[0].length === 0) {\n notMatrices.add(matrix)\n return false\n }\n const nbrOfCols = matrix[0].length\n for (const row of matrix) {\n if (!Array.isArray(row) || row.length !== nbrOfCols || row.some(cell => !isNumber(cell))) {\n notMatrices.add(matrix)\n return false\n }\n }\n annotatedArrays.add(matrix)\n grids.add(matrix)\n matrices.add(matrix)\n return true\n}\n\nexport function assertMatrix(matrix: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts matrix is number[][] {\n if (!isMatrix(matrix)) {\n throw new LitsError(`Expected a matrix, but got ${matrix}`, sourceCodeInfo)\n }\n}\n\nexport function assertSquareMatrix(matrix: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts matrix is number[][] {\n if (!isMatrix(matrix)) {\n throw new LitsError(`Expected a matrix, but got ${matrix}`, sourceCodeInfo)\n }\n if (matrix.length !== matrix[0]!.length) {\n throw new LitsError(`Expected square matrix, but got ${matrix.length} and ${matrix[0]!.length}`, sourceCodeInfo)\n }\n}\n\nexport function isSquareMatrix(matrix: unknown): matrix is number[][] {\n if (!isMatrix(matrix)) {\n return false\n }\n if (matrix.length !== matrix[0]!.length) {\n return false\n }\n return true\n}\n","import { LitsError } from '../errors'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { valueToString } from './debug/debugTools'\nimport { getSourceCodeInfo } from './debug/getSourceCodeInfo'\n\nexport function getAssertionError(typeName: string, value: unknown, sourceCodeInfo?: SourceCodeInfo): LitsError {\n return new LitsError(`Expected ${typeName}, got ${valueToString(value)}.`, getSourceCodeInfo(value, sourceCodeInfo))\n}\n","import type { SourceCodeInfo } from '../tokenizer/token'\nimport { getAssertionError } from '../utils/getAssertionError'\n\n// isArray not needed, use Array.isArary\nexport function asArray(value: unknown, sourceCodeInfo?: SourceCodeInfo): unknown[] {\n assertArray(value, sourceCodeInfo)\n return value\n}\nexport function assertArray(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is unknown[] {\n if (!Array.isArray(value))\n throw getAssertionError('array', value, sourceCodeInfo)\n}\n\nexport function isStringArray(value: unknown): value is string[] {\n return Array.isArray(value) && value.every(v => typeof v === 'string')\n}\nexport function asStringArray(value: unknown, sourceCodeInfo?: SourceCodeInfo): string[] {\n assertStringArray(value, sourceCodeInfo)\n return value\n}\nexport function assertStringArray(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is string[] {\n if (!isStringArray(value))\n throw getAssertionError('array of strings', value, sourceCodeInfo)\n}\n\nexport function isCharArray(value: unknown): value is string[] {\n return Array.isArray(value) && value.every(v => typeof v === 'string' && v.length === 1)\n}\nexport function asCharArray(value: unknown, sourceCodeInfo?: SourceCodeInfo): string[] {\n assertCharArray(value, sourceCodeInfo)\n return value\n}\nexport function assertCharArray(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is string[] {\n if (!isCharArray(value))\n throw getAssertionError('array of strings', value, sourceCodeInfo)\n}\n","import type { LitsFunction, NativeJsFunction, NormalBuiltinFunction, UserDefinedFunction } from '../parser/types'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { getAssertionError } from '../utils/getAssertionError'\nimport { FUNCTION_SYMBOL } from '../utils/symbols'\nimport { isUnknownRecord } from '.'\n\nexport function isLitsFunction(value: unknown): value is LitsFunction {\n if (value === null || typeof value !== 'object')\n return false\n\n return !!(value as LitsFunction)[FUNCTION_SYMBOL]\n}\nexport function asLitsFunction(value: unknown, sourceCodeInfo?: SourceCodeInfo): LitsFunction {\n assertLitsFunction(value, sourceCodeInfo)\n return value\n}\nexport function assertLitsFunction(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is LitsFunction {\n if (!isLitsFunction(value))\n throw getAssertionError('LitsFunction', value, sourceCodeInfo)\n}\n\nexport function isUserDefinedFunction(value: unknown): value is UserDefinedFunction {\n return isLitsFunction(value) && value.functionType === 'UserDefined'\n}\nexport function asUserDefinedFunction(value: unknown, sourceCodeInfo?: SourceCodeInfo): UserDefinedFunction {\n assertUserDefinedFunction(value, sourceCodeInfo)\n return value\n}\nexport function assertUserDefinedFunction(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n): asserts value is UserDefinedFunction {\n if (!isUserDefinedFunction(value))\n throw getAssertionError('NativeJsFunction', value, sourceCodeInfo)\n}\n\nexport function isNativeJsFunction(value: unknown): value is NativeJsFunction {\n return isLitsFunction(value) && value.functionType === 'NativeJsFunction'\n}\nexport function asNativeJsFunction(value: unknown, sourceCodeInfo?: SourceCodeInfo): NativeJsFunction {\n assertNativeJsFunction(value, sourceCodeInfo)\n return value\n}\nexport function assertNativeJsFunction(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n): asserts value is NativeJsFunction {\n if (!isNativeJsFunction(value))\n throw getAssertionError('NativeJsFunction', value, sourceCodeInfo)\n}\n\nexport function isBuiltinFunction(value: unknown): value is NormalBuiltinFunction {\n return isUnknownRecord(value) && value.functionType === 'Builtin'\n}\n","import type { Any, Coll, Obj, Seq } from '../interface'\nimport type { FunctionLike, RegularExpression } from '../parser/types'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { getAssertionError } from '../utils/getAssertionError'\nimport { REGEXP_SYMBOL } from '../utils/symbols'\nimport { isLitsFunction } from './litsFunction'\n\nexport function isAny(value: unknown): value is Any {\n // TODO weak test\n return value !== undefined\n}\nexport function asAny(value: unknown, sourceCodeInfo?: SourceCodeInfo): Any {\n assertAny(value, sourceCodeInfo)\n return value\n}\nexport function assertAny(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is Any {\n if (!isAny(value))\n throw getAssertionError('not undefined', value, sourceCodeInfo)\n}\n\nexport function isSeq(value: unknown): value is Seq {\n return Array.isArray(value) || typeof value === 'string'\n}\nexport function asSeq(value: unknown, sourceCodeInfo?: SourceCodeInfo): Seq {\n assertSeq(value, sourceCodeInfo)\n return value\n}\nexport function assertSeq(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is Seq {\n if (!isSeq(value))\n throw getAssertionError('string or array', value, sourceCodeInfo)\n}\n\nexport function isObj(value: unknown): value is Obj {\n return !(\n value === null\n || typeof value !== 'object'\n || Array.isArray(value)\n || value instanceof RegExp\n || isLitsFunction(value)\n || isRegularExpression(value)\n )\n}\nexport function asObj(value: unknown, sourceCodeInfo?: SourceCodeInfo): Obj {\n assertObj(value, sourceCodeInfo)\n return value\n}\nexport function assertObj(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is Obj {\n if (!isObj(value))\n throw getAssertionError('object', value, sourceCodeInfo)\n}\n\nexport function isColl(value: unknown): value is Coll {\n return isSeq(value) || isObj(value)\n}\nexport function asColl(value: unknown, sourceCodeInfo?: SourceCodeInfo): Coll {\n assertColl(value, sourceCodeInfo)\n return value\n}\nexport function assertColl(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is Coll {\n if (!isColl(value))\n throw getAssertionError('string, array or object', value, sourceCodeInfo)\n}\n\nexport function isRegularExpression(regexp: unknown): regexp is RegularExpression {\n if (regexp === null || typeof regexp !== 'object')\n return false\n\n return !!(regexp as RegularExpression)[REGEXP_SYMBOL]\n}\nexport function asRegularExpression(value: unknown, sourceCodeInfo?: SourceCodeInfo): RegularExpression {\n assertRegularExpression(value, sourceCodeInfo)\n return value\n}\nexport function assertRegularExpression(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n): asserts value is RegularExpression {\n if (!isRegularExpression(value))\n throw getAssertionError('RegularExpression', value, sourceCodeInfo)\n}\n\nexport function isStringOrRegularExpression(value: unknown): value is string | RegularExpression {\n return isRegularExpression(value) || typeof value === 'string'\n}\nexport function asStringOrRegularExpression(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n): string | RegularExpression {\n assertStringOrRegularExpression(value, sourceCodeInfo)\n return value\n}\nexport function assertStringOrRegularExpression(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n): asserts value is string | RegularExpression {\n if (!isStringOrRegularExpression(value))\n throw getAssertionError('string or RegularExpression', value, sourceCodeInfo)\n}\n\nfunction isFunctionLike(value: unknown): value is FunctionLike {\n if (typeof value === 'number')\n return true\n if (isColl(value))\n return true\n if (isLitsFunction(value))\n return true\n\n return false\n}\nexport function asFunctionLike(value: unknown, sourceCodeInfo?: SourceCodeInfo): FunctionLike {\n assertFunctionLike(value, sourceCodeInfo)\n return value\n}\nexport function assertFunctionLike(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is FunctionLike {\n if (!isFunctionLike(value))\n throw getAssertionError('FunctionLike', value, sourceCodeInfo)\n}\n","import type { Arity } from '../builtin/interface'\nimport { LitsError } from '../errors'\nimport type { FunctionLike } from '../parser/types'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { isColl } from '../typeGuards/lits'\nimport { valueToString } from './debug/debugTools'\n\nexport function arityAccepts(arity: Arity, nbrOfParams: number): boolean {\n const { min, max } = arity\n if (typeof min === 'number' && nbrOfParams < min) {\n return false\n }\n if (typeof max === 'number' && nbrOfParams > max) {\n return false\n }\n return true\n}\n\nexport function arityAcceptsMin(arity: Arity, nbrOfParams: number): boolean {\n const { min } = arity\n if (typeof min === 'number' && nbrOfParams < min) {\n return false\n }\n return true\n}\n\nexport function getCommonArityFromFunctions(params: FunctionLike[]): Arity | null {\n return params.reduce((acc: Arity | null, param): Arity | null => {\n if (acc === null) {\n return null\n }\n const arity: Arity = (typeof param === 'number' || isColl(param)) ? toFixedArity(1) : param.arity\n const { min: aMin, max: aMax } = arity\n const { min: bMin, max: bMax } = acc\n const min = typeof aMin === 'number' && typeof bMin === 'number'\n ? Math.max(aMin, bMin)\n : typeof aMin === 'number' ? aMin : typeof bMin === 'number' ? bMin : undefined\n const max = typeof aMax === 'number' && typeof bMax === 'number'\n ? Math.min(aMax, bMax)\n : typeof aMax === 'number' ? aMax : typeof bMax === 'number' ? bMax : undefined\n\n if (typeof min === 'number' && typeof max === 'number' && min > max) {\n return null\n }\n\n return { min, max }\n }, {})\n}\n\nexport function getArityFromFunction(param: FunctionLike): Arity {\n return (typeof param === 'number' || isColl(param)) ? toFixedArity(1) : param.arity\n}\n\nexport function assertNumberOfParams(arity: Arity, length: number, sourceCodeInfo: SourceCodeInfo | undefined): void {\n const { min, max } = arity\n if (typeof min === 'number' && length < min) {\n throw new LitsError(\n `Wrong number of arguments, expected at least ${min}, got ${valueToString(length)}.`,\n sourceCodeInfo,\n )\n }\n\n if (typeof max === 'number' && length > max) {\n throw new LitsError(\n `Wrong number of arguments, expected at most ${max}, got ${valueToString(length)}.`,\n sourceCodeInfo,\n )\n }\n}\n\nexport function canBeOperator(count: Arity): boolean {\n if (typeof count.max === 'number' && count.max < 2) {\n return false\n }\n\n if (typeof count.min === 'number' && count.min > 2) {\n return false\n }\n\n return true\n}\n\nexport function toFixedArity(arity: number): Arity {\n return { min: arity, max: arity }\n}\n","import type { FunctionDocs } from '../../interface'\n\nexport const moduleDocs: Record<string, FunctionDocs> = {\n 'every?': {\n category: 'grid',\n 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.',\n returns: {\n type: 'boolean',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n '// 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?)',\n '// 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?)',\n '// 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?)',\n ],\n seeAlso: ['collection.every?', 'grid.some?', 'grid.every-row?', 'grid.every-col?'],\n },\n 'some?': {\n category: 'grid',\n 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.',\n returns: {\n type: 'boolean',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { some? } = import(\"grid\");\\nsome?([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], string?)',\n 'let { some? } = import(\"grid\");\\nsome?([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n], string?)',\n 'let { some? } = import(\"grid\");\\nsome?([\\n [1, 2],\\n [3, 4],\\n], string?)',\n ],\n seeAlso: ['collection.any?', 'grid.every?', 'grid.some-row?', 'grid.some-col?'],\n },\n 'every-row?': {\n category: 'grid',\n 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.',\n returns: {\n type: 'boolean',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { every-row? } = import(\"grid\");\\nevery-row?([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], -> string?($[0]))',\n 'let { every-row? } = import(\"grid\");\\nevery-row?([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n], -> string?($[0]))',\n 'let { every-row? } = import(\"grid\");\\nevery-row?([\\n [1, 2],\\n [3, 4],\\n], -> string?($[0]))',\n ],\n seeAlso: ['grid.some-row?', 'grid.every-col?', 'grid.every?'],\n },\n 'some-row?': {\n category: 'grid',\n 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.',\n returns: {\n type: 'boolean',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { some-row? } = import(\"grid\");\\nsome-row?([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], -> $ contains? \"Albert\")',\n 'let { some-row? } = import(\"grid\");\\nsome-row?([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n], -> $ contains? \"Albert\")',\n 'let { some-row? } = import(\"grid\");\\nsome-row?([\\n [1, 2],\\n [3, 4],\\n], -> $ contains? \"Albert\")',\n ],\n seeAlso: ['grid.every-row?', 'grid.some-col?', 'grid.some?'],\n },\n 'every-col?': {\n category: 'grid',\n 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.',\n returns: {\n type: 'boolean',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { every-col? } = import(\"grid\");\\nevery-col?([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], -> string?($[0]))',\n 'let { every-col? } = import(\"grid\");\\nevery-col?([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n], -> string?($[0]))',\n 'let { every-col? } = import(\"grid\");\\nevery-col?([\\n [1, 2],\\n [3, 4],\\n], -> string?($[0]))',\n ],\n seeAlso: ['grid.some-col?', 'grid.every-row?', 'grid.every?'],\n },\n 'some-col?': {\n category: 'grid',\n 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.',\n returns: {\n type: 'boolean',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { some-col? } = import(\"grid\");\\nsome-col?([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], -> $ contains? \"Albert\")',\n 'let { some-col? } = import(\"grid\");\\nsome-col?([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n], -> $ contains? \"Albert\")',\n 'let { some-col? } = import(\"grid\");\\nsome-col?([\\n [1, 2],\\n [3, 4],\\n], -> $ contains? \"Albert\")',\n ],\n seeAlso: ['grid.every-col?', 'grid.some-row?', 'grid.some?'],\n },\n 'row': {\n category: 'grid',\n description: 'Returns the row at index $a in the grid $b.',\n returns: {\n type: 'any',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'number',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { row } = import(\"grid\");\\nrow([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 0)',\n 'let { row } = import(\"grid\");\\nrow([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1)',\n 'let { row } = import(\"grid\");\\nrow([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 2)',\n ],\n seeAlso: ['grid.col', 'grid.shape'],\n },\n 'col': {\n category: 'grid',\n description: 'Returns the column at index $a in the grid $b.',\n returns: {\n type: 'any',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'number',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { col } = import(\"grid\");\\ncol([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 0)',\n 'let { col } = import(\"grid\");\\ncol([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1)',\n 'let { col } = import(\"grid\");\\ncol([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 2)',\n ],\n seeAlso: ['grid.row', 'grid.shape'],\n },\n 'shape': {\n category: 'grid',\n 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.',\n returns: {\n type: 'vector',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to get the shape of.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { shape } = import(\"grid\");\\nshape([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n 'let { shape } = import(\"grid\");\\nshape([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n])',\n 'let { shape } = import(\"grid\");\\nshape([\\n [1, 2],\\n [3, 4],\\n])',\n ],\n seeAlso: ['grid.row', 'grid.col', 'grid.reshape'],\n },\n 'fill': {\n category: 'grid',\n description: 'Creates a grid of the specified size, filled with the specified value.',\n returns: {\n type: 'grid',\n },\n args: {\n rows: {\n type: 'integer',\n description: 'The number of rows in the grid.',\n },\n cols: {\n type: 'integer',\n description: 'The number of columns in the grid.',\n },\n value: {\n type: 'any',\n description: 'The value to fill the grid with.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'rows',\n 'cols',\n 'value',\n ],\n },\n ],\n examples: [\n 'let { fill } = import(\"grid\");\\nfill(2, 3, 0)',\n 'let { fill } = import(\"grid\");\\nfill(2, 3, \"x\")',\n ],\n seeAlso: ['grid.generate', 'grid.from-array', 'vector.fill'],\n },\n 'generate': {\n category: 'grid',\n description: 'Generates a grid of the specified size, where each element is generated by the provided function.',\n returns: {\n type: 'grid',\n },\n args: {\n rows: {\n type: 'number',\n description: 'The number of rows in the grid.',\n },\n cols: {\n type: 'number',\n description: 'The number of columns in the grid.',\n },\n fn: {\n type: 'function',\n description: 'The function to generate the grid. It takes two arguments: the row index and the column index.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'rows',\n 'cols',\n 'fn',\n ],\n },\n ],\n examples: [\n 'let { generate } = import(\"grid\");\\ngenerate(3, 3, (i, j) -> i + j)',\n ],\n seeAlso: ['grid.fill', 'grid.from-array', 'vector.generate'],\n },\n 'reshape': {\n category: 'grid',\n 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.',\n returns: {\n type: 'grid',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'number',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { reshape } = import(\"grid\");\\nreshape([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n], 2)',\n ],\n seeAlso: ['grid.shape', 'grid.from-array'],\n },\n 'transpose': {\n category: 'grid',\n description: 'Transposes the grid `g`, swapping its rows and columns.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to transpose.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { transpose } = import(\"grid\");\\ntranspose([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n 'let { transpose } = import(\"grid\");\\ntranspose([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n])',\n 'let { transpose } = import(\"grid\");\\ntranspose([\\n [1, 2],\\n [3, 4],\\n])',\n ],\n seeAlso: ['grid.flip-h', 'grid.flip-v', 'grid.rotate'],\n },\n 'flip-h': {\n category: 'grid',\n description: 'Flips the grid `g` horizontally.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to flip horizontally.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { flip-h } = import(\"grid\");\\nflip-h([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n 'let { flip-h } = import(\"grid\");\\nflip-h([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n])',\n 'let { flip-h } = import(\"grid\");\\nflip-h([\\n [1, 2],\\n [3, 4],\\n])',\n ],\n seeAlso: ['grid.flip-v', 'grid.transpose', 'grid.rotate', 'grid.reverse-cols'],\n },\n 'flip-v': {\n category: 'grid',\n description: 'Flips the grid `g` vertically.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to flip vertically.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { flip-v } = import(\"grid\");\\nflip-v([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n 'let { flip-v } = import(\"grid\");\\nflip-v([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n])',\n 'let { flip-v } = import(\"grid\");\\nflip-v([\\n [1, 2],\\n [3, 4],\\n])',\n ],\n seeAlso: ['grid.flip-h', 'grid.transpose', 'grid.rotate', 'grid.reverse-rows'],\n },\n 'rotate': {\n category: 'grid',\n 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.',\n returns: {\n type: 'grid',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'integer',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { rotate } = import(\"grid\");\\nrotate([\\n [1, 2],\\n [3, 4],\\n], 1)',\n 'let { rotate } = import(\"grid\");\\nrotate([\\n [1, 2],\\n [3, 4],\\n], 2)',\n 'let { rotate } = import(\"grid\");\\nrotate([\\n [1, 2],\\n [3, 4],\\n], 3)',\n 'let { rotate } = import(\"grid\");\\nrotate([\\n [1, 2],\\n [3, 4],\\n], 4)',\n 'let { rotate } = import(\"grid\");\\nrotate([\\n [1, 2],\\n [3, 4],\\n], -1)',\n 'let { rotate } = import(\"grid\");\\nrotate([\\n [1, 2],\\n [3, 4],\\n], -2)',\n 'let { rotate } = import(\"grid\");\\nrotate([\\n [1, 2],\\n [3, 4],\\n], -3)',\n ],\n seeAlso: ['grid.transpose', 'grid.flip-h', 'grid.flip-v'],\n },\n 'reverse-rows': {\n category: 'grid',\n description: 'Reverses the order of rows in the grid `g`.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to reverse rows.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { reverse-rows } = import(\"grid\");\\nreverse-rows([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n 'let { reverse-rows } = import(\"grid\");\\nreverse-rows([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n])',\n 'let { reverse-rows } = import(\"grid\");\\nreverse-rows([\\n [1, 2],\\n [3, 4],\\n])',\n ],\n seeAlso: ['grid.reverse-cols', 'grid.flip-v'],\n },\n 'reverse-cols': {\n category: 'grid',\n description: 'Reverses the order of columns in the grid `g`.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to reverse columns.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { reverse-cols } = import(\"grid\");\\nreverse-cols([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n 'let { reverse-cols } = import(\"grid\");\\nreverse-cols([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n])',\n 'let { reverse-cols } = import(\"grid\");\\nreverse-cols([\\n [1, 2],\\n [3, 4],\\n])',\n ],\n seeAlso: ['grid.reverse-rows', 'grid.flip-h'],\n },\n 'slice': {\n category: 'grid',\n 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.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to slice.',\n },\n begin: {\n type: 'vector',\n description: 'The starting index of the slice as a vector of two numbers: `[row, col]`.',\n },\n stop: {\n type: 'vector',\n description: 'Optional ending index of the slice as a vector of two numbers: `[row, col]`.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'begin',\n ],\n },\n {\n argumentNames: [\n 'g',\n 'begin',\n 'stop',\n ],\n },\n ],\n examples: [\n '// 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])',\n '// 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])',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.slice-rows', 'grid.slice-cols'],\n },\n 'slice-rows': {\n category: 'grid',\n 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.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to slice.',\n },\n begin: {\n type: 'number',\n description: 'The starting index of the slice.',\n },\n stop: {\n type: 'number',\n description: 'Optional ending index of the slice.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'begin',\n ],\n },\n {\n argumentNames: [\n 'g',\n 'begin',\n 'stop',\n ],\n },\n ],\n examples: [\n 'let { slice-rows } = import(\"grid\");\\nslice-rows([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1, 2)',\n 'let { slice-rows } = import(\"grid\");\\nslice-rows([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1)',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.slice', 'grid.slice-cols', 'grid.splice-rows'],\n },\n 'slice-cols': {\n category: 'grid',\n 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.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to slice.',\n },\n begin: {\n type: 'number',\n description: 'The starting index of the slice.',\n },\n stop: {\n type: 'number',\n description: 'Optional ending index of the slice.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'begin',\n ],\n },\n {\n argumentNames: [\n 'g',\n 'begin',\n 'stop',\n ],\n },\n ],\n examples: [\n 'let { slice-cols } = import(\"grid\");\\nslice-cols([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1, 2)',\n 'let { slice-cols } = import(\"grid\");\\nslice-cols([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1)',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.slice', 'grid.slice-rows', 'grid.splice-cols'],\n },\n 'splice-rows': {\n category: 'grid',\n description: 'Splices rows of the grid `g` starting from the index `begin`. Deletes `deleteCount` rows and inserts the specified `items` at that position.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to splice.',\n },\n begin: {\n type: 'number',\n description: 'The starting index of the splice.',\n },\n deleteCount: {\n type: 'number',\n description: 'The number of rows to delete.',\n },\n items: {\n type: 'array',\n rest: true,\n description: 'The rows to insert.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'begin',\n 'deleteCount',\n ],\n },\n {\n argumentNames: [\n 'g',\n 'begin',\n 'deleteCount',\n 'items',\n ],\n },\n ],\n examples: [\n 'let { splice-rows } = import(\"grid\");\\nsplice-rows([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1, 2)',\n '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])',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.splice-cols', 'grid.slice-rows'],\n },\n 'splice-cols': {\n category: 'grid',\n description: 'Splices columns of the grid `g` starting from the index `begin`. Deletes `deleteCount` columns and inserts the specified `items` at that position.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to splice.',\n },\n begin: {\n type: 'number',\n description: 'The starting index of the splice.',\n },\n deleteCount: {\n type: 'number',\n description: 'The number of columns to delete.',\n },\n items: {\n type: 'array',\n rest: true,\n description: 'The columns to insert.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'begin',\n 'deleteCount',\n ],\n },\n {\n argumentNames: [\n 'g',\n 'begin',\n 'deleteCount',\n 'items',\n ],\n },\n ],\n examples: [\n 'let { splice-cols } = import(\"grid\");\\nsplice-cols([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1, 2)',\n '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\"])',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.splice-rows', 'grid.slice-cols'],\n },\n 'concat-rows': {\n category: 'grid',\n description: 'Concatenates two grids `a` and `b` by rows. The number of columns in both grids must be the same.',\n returns: {\n type: 'grid',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'grid',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { concat-rows } = import(\"grid\");\\nconcat-rows([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n], [\\n [1, 2],\\n [3, 4],\\n])',\n ],\n seeAlso: ['grid.concat-cols', 'grid.push-rows'],\n },\n 'concat-cols': {\n category: 'grid',\n description: 'Concatenates two grids `a` and `b` by columns. The number of rows in both grids must be the same.',\n returns: {\n type: 'grid',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'grid',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n '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])',\n ],\n seeAlso: ['grid.concat-rows', 'grid.push-cols'],\n },\n 'map': {\n category: 'grid',\n description: 'Maps a function `a` over each element of the grid `b`, returning a new grid with the results.',\n returns: {\n type: 'grid',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n '// 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)',\n ],\n seeAlso: ['map', 'grid.mapi', 'grid.reduce'],\n },\n 'mapi': {\n category: 'grid',\n description: 'Maps a function `a` over each element of the grid `b`, passing the row and column index as additional arguments to the function.',\n returns: {\n type: 'grid',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n '// 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 ++ \")\")',\n ],\n seeAlso: ['grid.map', 'grid.reducei', 'map'],\n },\n 'reduce': {\n category: 'grid',\n description: 'Reduces the grid `a` using the function `b`, returning a single value.',\n returns: {\n type: 'any',\n },\n args: {\n 'g': {\n type: 'grid',\n description: 'The grid to reduce.',\n },\n 'fn': {\n type: 'function',\n description: 'The function to reduce the grid. It takes two arguments: the accumulator and the current element.',\n },\n 'initial-value': {\n type: 'any',\n description: 'The initial value for the accumulator.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'fn',\n 'initial-value',\n ],\n },\n ],\n examples: [\n '// 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], ++, \"\")',\n ],\n seeAlso: ['reduce', 'grid.reducei', 'grid.map'],\n },\n 'reducei': {\n category: 'grid',\n description: 'Reduces the grid `a` using the function `b`, passing the row and column indices as additional arguments to the function.',\n returns: {\n type: 'any',\n },\n args: {\n 'g': {\n type: 'grid',\n description: 'The grid to reduce.',\n },\n 'fn': {\n type: 'function',\n description: 'The function to reduce the grid. It takes four arguments: the accumulator, the current element, the row index, and the column index.',\n },\n 'initial-value': {\n type: 'any',\n description: 'The initial value for the accumulator.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'fn',\n 'initial-value',\n ],\n },\n ],\n examples: [\n '// 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], ++, \"\")',\n ],\n seeAlso: ['grid.reduce', 'grid.mapi', 'reduce'],\n },\n 'push-rows': {\n category: 'grid',\n description: 'Pushes the specified rows into the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to push rows into.',\n },\n rows: {\n type: 'array',\n rest: true,\n description: 'The rows to push into the grid.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'rows',\n ],\n },\n ],\n examples: [\n 'let { push-rows } = import(\"grid\");\\npush-rows([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], [\"Nazanin\", \"mother\", 40])',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.unshift-rows', 'grid.pop-row', 'grid.shift-row', 'grid.concat-rows'],\n },\n 'unshift-rows': {\n category: 'grid',\n description: 'Unshifts the specified rows into the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to unshift rows into.',\n },\n rows: {\n type: 'array',\n rest: true,\n description: 'The rows to unshift into the grid.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'rows',\n ],\n },\n ],\n examples: [\n 'let { unshift-rows } = import(\"grid\");\\nunshift-rows([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], [\"Nazanin\", \"mother\", 40])',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.push-rows', 'grid.shift-row', 'grid.pop-row'],\n },\n 'pop-row': {\n category: 'grid',\n description: 'Pops the last row from the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to pop a row from.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { pop-row } = import(\"grid\");\\npop-row([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n ],\n seeAlso: ['grid.shift-row', 'grid.push-rows', 'grid.unshift-rows'],\n },\n 'shift-row': {\n category: 'grid',\n description: 'Shifts the first row from the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to shift a row from.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { shift-row } = import(\"grid\");\\nshift-row([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n ],\n seeAlso: ['grid.pop-row', 'grid.push-rows', 'grid.unshift-rows'],\n },\n 'push-cols': {\n category: 'grid',\n description: 'Pushes the specified columns into the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to push columns into.',\n },\n cols: {\n type: 'array',\n rest: true,\n description: 'The columns to push into the grid.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'cols',\n ],\n },\n ],\n examples: [\n 'let { push-cols } = import(\"grid\");\\npush-cols([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], [\"f\", \"m\", \"s\"])',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.unshift-cols', 'grid.pop-col', 'grid.shift-col', 'grid.concat-cols'],\n },\n 'unshift-cols': {\n category: 'grid',\n description: 'Unshifts the specified columns into the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to unshift columns into.',\n },\n cols: {\n type: 'array',\n rest: true,\n description: 'The columns to unshift into the grid.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'cols',\n ],\n },\n ],\n examples: [\n 'let { unshift-cols } = import(\"grid\");\\nunshift-cols([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], [\"f\", \"m\", \"s\"])',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.push-cols', 'grid.shift-col', 'grid.pop-col'],\n },\n 'pop-col': {\n category: 'grid',\n description: 'Pops the last column from the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to pop a column from.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { pop-col } = import(\"grid\");\\npop-col([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n ],\n seeAlso: ['grid.shift-col', 'grid.push-cols', 'grid.unshift-cols'],\n },\n 'shift-col': {\n category: 'grid',\n description: 'Shifts the first column from the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to shift a column from.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { shift-col } = import(\"grid\");\\nshift-col([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n ],\n seeAlso: ['grid.pop-col', 'grid.push-cols', 'grid.unshift-cols'],\n },\n 'from-array': {\n category: 'grid',\n 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.',\n returns: {\n type: 'grid',\n },\n args: {\n a: {\n type: 'array',\n },\n b: {\n type: 'number',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { from-array } = import(\"grid\");\\nfrom-array([1, 2, 3, 4], 2)',\n 'let { from-array } = import(\"grid\");\\nfrom-array([1, 2, 3, 4], 4)',\n ],\n seeAlso: ['grid.fill', 'grid.generate', 'grid.reshape'],\n },\n}\n","import type { Any } from '../../../interface'\n\nexport function transpose<T extends Any>(grid: T[][]): T[][] {\n const result: T[][] = []\n\n for (let i = 0; i < grid[0]!.length; i += 1) {\n const row: T[] = []\n for (let j = 0; j < grid.length; j += 1) {\n row.push(grid[j]![i]!)\n }\n result.push(row)\n }\n return result\n}\n","import { LitsError } from '../../../errors'\nimport type { Any } from '../../../interface'\nimport { assertGrid, assertVector } from '../../../typeGuards/annotatedArrays'\nimport { assertArray } from '../../../typeGuards/array'\nimport { asAny, asFunctionLike, assertAny, assertFunctionLike } from '../../../typeGuards/lits'\nimport { assertNumber } from '../../../typeGuards/number'\nimport { toFixedArity } from '../../../utils/arity'\nimport type { BuiltinNormalExpressions } from '../../../builtin/interface'\nimport type { LitsModule } from '../interface'\nimport { moduleDocs } from './docs'\nimport { fromArray } from './fromArray'\nimport { transpose } from './transpose'\n\nconst gridFunctions: BuiltinNormalExpressions = {\n 'every?': {\n evaluate: ([grid, predicate], sourceCodeInfo, contextStack, { executeFunction }): boolean => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(predicate, sourceCodeInfo)\n\n for (const row of grid) {\n for (const cell of row) {\n if (!executeFunction(predicate, [cell], contextStack, sourceCodeInfo)) {\n return false\n }\n }\n }\n return true\n },\n arity: toFixedArity(2),\n },\n 'some?': {\n evaluate: ([grid, predicate], sourceCodeInfo, contextStack, { executeFunction }): boolean => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(predicate, sourceCodeInfo)\n\n for (const row of grid) {\n for (const cell of row) {\n if (executeFunction(predicate, [cell], contextStack, sourceCodeInfo)) {\n return true\n }\n }\n }\n return false\n },\n arity: toFixedArity(2),\n },\n 'every-row?': {\n evaluate: ([grid, predicate], sourceCodeInfo, contextStack, { executeFunction }): boolean => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(predicate, sourceCodeInfo)\n\n for (const row of grid) {\n if (!executeFunction(predicate, [row], contextStack, sourceCodeInfo)) {\n return false\n }\n }\n return true\n },\n arity: toFixedArity(2),\n },\n 'some-row?': {\n evaluate: ([grid, predicate], sourceCodeInfo, contextStack, { executeFunction }): boolean => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(predicate, sourceCodeInfo)\n\n for (const row of grid) {\n if (executeFunction(predicate, [row], contextStack, sourceCodeInfo)) {\n return true\n }\n }\n return false\n },\n arity: toFixedArity(2),\n },\n 'every-col?': {\n evaluate: ([grid, predicate], sourceCodeInfo, contextStack, { executeFunction }): boolean => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(predicate, sourceCodeInfo)\n\n const transposed = transpose(grid)\n for (const row of transposed) {\n if (!executeFunction(predicate, [row], contextStack, sourceCodeInfo)) {\n return false\n }\n }\n return true\n },\n arity: toFixedArity(2),\n },\n 'some-col?': {\n evaluate: ([grid, predicate], sourceCodeInfo, contextStack, { executeFunction }): boolean => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(predicate, sourceCodeInfo)\n\n const transposed = transpose(grid)\n for (const row of transposed) {\n if (executeFunction(predicate, [row], contextStack, sourceCodeInfo)) {\n return true\n }\n }\n return false\n },\n arity: toFixedArity(2),\n },\n 'row': {\n evaluate: ([grid, row], sourceCodeInfo): Any[] => {\n assertGrid(grid, sourceCodeInfo)\n assertNumber(row, sourceCodeInfo, { integer: true, nonNegative: true, lt: grid.length })\n return grid[row]!\n },\n arity: toFixedArity(2),\n },\n 'col': {\n evaluate: ([grid, col], sourceCodeInfo): Any[] => {\n assertGrid(grid, sourceCodeInfo)\n assertNumber(col, sourceCodeInfo, { integer: true, nonNegative: true, lt: grid[0]!.length })\n return grid.map(row => row[col]!)\n },\n arity: toFixedArity(2),\n },\n 'shape': {\n evaluate: ([grid], sourceCodeInfo): Any[] => {\n assertGrid(grid, sourceCodeInfo)\n return [grid.length, grid[0]!.length]\n },\n arity: toFixedArity(1),\n },\n 'fill': {\n evaluate: ([rows, cols, value], sourceCodeInfo): Any[][] => {\n assertNumber(rows, sourceCodeInfo, { integer: true, positive: true })\n assertNumber(cols, sourceCodeInfo, { integer: true, positive: true })\n assertAny(value, sourceCodeInfo)\n const result: Any[][] = []\n for (let i = 0; i < rows; i += 1) {\n const row: Any[] = []\n for (let j = 0; j < cols; j += 1) {\n row.push(value)\n }\n result.push(row)\n }\n return result\n },\n arity: toFixedArity(3),\n },\n 'generate': {\n evaluate: ([rows, cols, generator], sourceCodeInfo, contextStack, { executeFunction }): Any[][] => {\n assertNumber(rows, sourceCodeInfo, { integer: true, positive: true })\n assertNumber(cols, sourceCodeInfo, { integer: true, positive: true })\n assertFunctionLike(generator, sourceCodeInfo)\n\n const result: Any[][] = []\n for (let i = 0; i < rows; i += 1) {\n const row: Any[] = []\n for (let j = 0; j < cols; j += 1) {\n const value = executeFunction(generator, [i, j], contextStack, sourceCodeInfo)\n assertAny(value, sourceCodeInfo)\n row.push(value)\n }\n result.push(row)\n }\n return result\n },\n arity: toFixedArity(3),\n },\n 'reshape': {\n evaluate: ([grid, rows], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertNumber(rows, sourceCodeInfo, { integer: true, positive: true })\n\n const flatTable = grid.flat()\n if (flatTable.length % rows !== 0) {\n throw new LitsError(`The number of elements in the grid must be divisible by rows, but got ${flatTable.length} and ${rows}`, sourceCodeInfo)\n }\n const cols = flatTable.length / rows\n\n const result: Any[][] = []\n for (let i = 0; i < rows; i += 1) {\n const row: Any[] = []\n for (let j = 0; j < cols; j += 1) {\n row.push(flatTable[i * cols + j]!)\n }\n result.push(row)\n }\n return result\n },\n arity: toFixedArity(2),\n },\n 'transpose': {\n evaluate: ([grid], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n return transpose(grid)\n },\n arity: toFixedArity(1),\n },\n 'flip-h': {\n evaluate: ([grid], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n return grid.map(row => row.reverse())\n },\n arity: toFixedArity(1),\n },\n 'flip-v': {\n evaluate: ([grid], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n return grid.reverse()\n },\n arity: toFixedArity(1),\n },\n 'rotate': {\n evaluate: ([grid, times], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertNumber(times, sourceCodeInfo, { integer: true })\n // Normalize times to be between 0 and 3\n times = ((times % 4) + 4) % 4\n\n // If times is 0, return the original grid\n if (times === 0 || grid.length === 0) {\n return grid.map(row => [...row])\n }\n\n const height = grid.length\n const width = grid[0]!.length\n\n let result: Any[][]\n\n switch (times) {\n case 1: // 90 degrees clockwise\n result = Array<Any>(width).fill(null).map(() => Array<Any>(height).fill(null))\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n result[x]![height - 1 - y] = grid[y]![x]!\n }\n }\n break\n\n case 2: // 180 degrees\n result = Array<Any>(height).fill(null).map(() => Array<Any>(width).fill(null))\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n result[height - 1 - y]![width - 1 - x] = grid[y]![x]!\n }\n }\n break\n\n case 3: // 270 degrees clockwise (or 90 degrees counter-clockwise)\n result = Array<Any>(width).fill(null).map(() => Array<Any>(height).fill(null))\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n result[width - 1 - x]![y] = grid[y]![x]!\n }\n }\n break\n }\n\n return result!\n },\n arity: toFixedArity(2),\n },\n 'reverse-rows': {\n evaluate: ([grid], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n return grid.reverse()\n },\n arity: toFixedArity(1),\n },\n 'reverse-cols': {\n evaluate: ([grid], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n return grid.map(row => row.reverse())\n },\n arity: toFixedArity(1),\n },\n 'slice': {\n evaluate: ([grid, start, end], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertVector(start, sourceCodeInfo)\n if (start.length !== 2) {\n throw new LitsError(`The start vector must have 2 elements, but got ${start.length}`, sourceCodeInfo)\n }\n const [rowStart, colStart] = start\n assertNumber(rowStart, sourceCodeInfo, { integer: true, nonNegative: true, lt: grid.length })\n assertNumber(colStart, sourceCodeInfo, { integer: true, nonNegative: true, lt: grid[0]!.length })\n\n end ??= [grid.length, grid[0]!.length]\n assertVector(end, sourceCodeInfo)\n if (end.length !== 2) {\n throw new LitsError(`The end vector must have 2 elements, but got ${end.length}`, sourceCodeInfo)\n }\n const [rowEnd, colEnd] = end\n assertNumber(rowEnd, sourceCodeInfo, { gt: rowStart, lte: grid.length })\n assertNumber(colEnd, sourceCodeInfo, { gt: colStart, lte: grid[0]!.length })\n\n const result: Any[][] = []\n for (let i = rowStart; i < rowEnd; i += 1) {\n const row: Any[] = []\n for (let j = colStart; j < colEnd; j += 1) {\n row.push(grid[i]![j]!)\n }\n result.push(row)\n }\n return result\n },\n arity: { min: 2, max: 3 },\n },\n 'slice-rows': {\n evaluate: ([grid, rowStart, rowEnd], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n\n if (typeof rowEnd === 'undefined') {\n assertNumber(rowStart, sourceCodeInfo, { integer: true, lte: grid.length, gte: -grid.length })\n if (rowStart < 0) {\n return grid.slice(grid.length + rowStart)\n }\n return grid.slice(rowStart)\n }\n\n assertNumber(rowStart, sourceCodeInfo, { integer: true, nonNegative: true, lte: grid.length })\n assertNumber(rowEnd, sourceCodeInfo, { integer: true })\n rowEnd = rowEnd < 0 ? grid.length + rowEnd : rowEnd\n assertNumber(rowEnd, sourceCodeInfo, { gt: rowStart, lte: grid.length })\n\n return grid.slice(rowStart, rowEnd)\n },\n arity: { min: 2, max: 3 },\n },\n 'slice-cols': {\n evaluate: ([grid, colStart, colEnd], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n const trMatrix = transpose(grid)\n\n if (typeof colEnd === 'undefined') {\n assertNumber(colStart, sourceCodeInfo, { integer: true, lte: trMatrix.length, gte: -trMatrix.length })\n if (colStart < 0) {\n return transpose(trMatrix.slice(trMatrix.length + colStart))\n }\n return transpose(trMatrix.slice(colStart))\n }\n\n assertNumber(colStart, sourceCodeInfo, { integer: true, nonNegative: true, lte: trMatrix.length })\n assertNumber(colEnd, sourceCodeInfo, { integer: true })\n colEnd = colEnd < 0 ? trMatrix.length + colEnd : colEnd\n assertNumber(colEnd, sourceCodeInfo, { gt: colStart, lte: trMatrix.length })\n\n return transpose(trMatrix.slice(colStart, colEnd))\n },\n arity: { min: 2, max: 3 },\n },\n 'splice-rows': {\n evaluate: ([grid, rowStart, rowDeleteCount, ...rows], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertNumber(rowStart, sourceCodeInfo, { integer: true, nonNegative: true, lte: grid.length })\n assertNumber(rowDeleteCount, sourceCodeInfo, { integer: true, nonNegative: true })\n if (rows.length !== 0) {\n assertGrid(rows, sourceCodeInfo)\n rows.every((row) => {\n assertArray(row, sourceCodeInfo)\n if (grid[0]!.length !== row.length) {\n throw new LitsError(`All rows must have the same length as the number of columns in grid, but got ${row.length}`, sourceCodeInfo)\n }\n return true\n })\n }\n\n const result: Any[][] = []\n for (let i = 0; i < rowStart; i += 1) {\n result.push(grid[i]!)\n }\n if (rows.length > 0) {\n result.push(...(rows as Any[][]))\n }\n for (let i = rowStart + rowDeleteCount; i < grid.length; i += 1) {\n result.push(grid[i]!)\n }\n return result\n },\n arity: { min: 3 },\n },\n 'splice-cols': {\n evaluate: ([grid, colStart, colDeleteCount, ...cols], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n const trMatrix = transpose(grid)\n assertNumber(colStart, sourceCodeInfo, { integer: true, nonNegative: true, lte: trMatrix.length })\n assertNumber(colDeleteCount, sourceCodeInfo, { integer: true, nonNegative: true })\n\n if (cols.length !== 0) {\n assertGrid(cols, sourceCodeInfo)\n cols.every((row) => {\n assertArray(row, sourceCodeInfo)\n if (trMatrix[0]!.length !== row.length) {\n throw new LitsError(`All rows must have the same length as the number of rows in grid, but got ${row.length}`, sourceCodeInfo)\n }\n return true\n })\n }\n\n const result: Any[][] = []\n for (let i = 0; i < colStart; i += 1) {\n result.push(trMatrix[i]!)\n }\n result.push(...(cols as Any[][]))\n for (let i = colStart + colDeleteCount; i < trMatrix.length; i += 1) {\n result.push(trMatrix[i]!)\n }\n return transpose(result)\n },\n arity: { min: 3 },\n },\n 'concat-rows': {\n evaluate: (params, sourceCodeInfo): Any[][] => {\n assertArray(params, sourceCodeInfo)\n params.every(grid => assertGrid(grid, sourceCodeInfo))\n const cols = (params[0] as Any[][])[0]!.length\n ;(params as Any[][][]).slice(1).every((grid) => {\n if (grid[0]!.length !== cols) {\n throw new LitsError(`All grids must have the same number of columns, but got ${cols} and ${grid[0]!.length}`, sourceCodeInfo)\n }\n return true\n })\n\n const result: Any[][] = []\n ;(params as Any[][][]).forEach((grid) => {\n grid.forEach((row) => {\n result.push(row)\n })\n })\n return result\n },\n arity: { min: 1 },\n },\n 'concat-cols': {\n evaluate: (params, sourceCodeInfo): Any[][] => {\n assertArray(params, sourceCodeInfo)\n params.every(grid => assertGrid(grid, sourceCodeInfo))\n const rows = (params[0] as Any[][]).length\n ;(params as Any[][][]).slice(1).every((grid) => {\n if (grid.length !== rows) {\n throw new LitsError(`All grids must have the same number of rows, but got ${rows} and ${grid.length}`, sourceCodeInfo)\n }\n return true\n })\n\n const result: Any[][] = []\n for (let i = 0; i < rows; i += 1) {\n const row: Any[] = []\n ;(params as Any[][][]).forEach((grid) => {\n row.push(...grid[i]!)\n })\n result.push(row)\n }\n return result\n },\n arity: { min: 1 },\n },\n 'map': {\n evaluate: (params, sourceCodeInfo, contextStack, { executeFunction }): Any[][] => {\n const fn = asFunctionLike(params.at(-1), sourceCodeInfo)\n const grids = params.slice(0, -1)\n assertGrid(grids[0], sourceCodeInfo)\n const rows = grids[0].length\n const cols = grids[0][0]!.length\n grids.slice(1).forEach((grid) => {\n assertGrid(grid, sourceCodeInfo)\n if (grid.length !== rows) {\n throw new LitsError(`All grids must have the same number of rows, but got ${rows} and ${grid.length}`, sourceCodeInfo)\n }\n if (grid[0]!.length !== cols) {\n throw new LitsError(`All grids must have the same number of columns, but got ${cols} and ${grid[0]!.length}`, sourceCodeInfo)\n }\n })\n\n const result: Any[][] = []\n for (let i = 0; i < rows; i += 1) {\n const row: Any[] = []\n for (let j = 0; j < cols; j += 1) {\n const args = grids.map(grid => (grid as Any[][])[i]![j])\n row.push(asAny(executeFunction(fn, args, contextStack, sourceCodeInfo)))\n }\n result.push(row)\n }\n return result\n },\n arity: { min: 2 },\n },\n 'mapi': {\n evaluate: ([grid, fn], sourceCodeInfo, contextStack, { executeFunction }): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(fn, sourceCodeInfo)\n\n const rows = grid.length\n const cols = grid[0]!.length\n\n const result: Any[][] = []\n for (let i = 0; i < rows; i += 1) {\n const row: Any[] = []\n for (let j = 0; j < cols; j += 1) {\n row.push(asAny(executeFunction(fn, [grid[i]![j], i, j], contextStack, sourceCodeInfo)))\n }\n result.push(row)\n }\n return result\n },\n arity: toFixedArity(2),\n },\n 'reduce': {\n evaluate: ([grid, fn, initialValue], sourceCodeInfo, contextStack, { executeFunction }): Any => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(fn, sourceCodeInfo)\n\n let accumulator = asAny(initialValue)\n for (const row of grid) {\n for (const cell of row) {\n accumulator = executeFunction(fn, [accumulator, cell], contextStack, sourceCodeInfo)\n }\n }\n return accumulator\n },\n arity: toFixedArity(3),\n },\n 'reducei': {\n evaluate: ([grid, fn, initialValue], sourceCodeInfo, contextStack, { executeFunction }): Any => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(fn, sourceCodeInfo)\n\n let accumulator = asAny(initialValue)\n for (let i = 0; i < grid.length; i += 1) {\n for (let j = 0; j < grid[i]!.length; j += 1) {\n accumulator = executeFunction(fn, [accumulator, grid[i]![j], i, j], contextStack, sourceCodeInfo)\n }\n }\n return accumulator\n },\n arity: toFixedArity(3),\n },\n 'push-rows': {\n evaluate: ([grid, ...rows], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertGrid(rows, sourceCodeInfo)\n if (grid[0]!.length !== rows[0]!.length) {\n throw new LitsError(`All rows must have the same length as the number of columns in grid, but got ${grid[0]!.length} and ${rows[0]!.length}`, sourceCodeInfo)\n }\n return [...grid, ...rows]\n },\n arity: { min: 2 },\n },\n 'unshift-rows': {\n evaluate: ([grid, ...rows], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertGrid(rows, sourceCodeInfo)\n if (grid[0]!.length !== rows[0]!.length) {\n throw new LitsError(`All rows must have the same length as the number of columns in grid, but got ${grid[0]!.length} and ${rows[0]!.length}`, sourceCodeInfo)\n }\n return [...rows, ...grid]\n },\n arity: { min: 2 },\n },\n 'pop-row': {\n evaluate: ([grid], sourceCodeInfo): Any[][] | null => {\n assertGrid(grid, sourceCodeInfo)\n if (grid.length === 1) {\n return null\n }\n return grid.slice(0, -1)\n },\n arity: toFixedArity(1),\n\n },\n 'shift-row': {\n evaluate: ([grid], sourceCodeInfo): Any[][] | null => {\n assertGrid(grid, sourceCodeInfo)\n if (grid.length === 1) {\n return null\n }\n return grid.slice(1)\n },\n arity: toFixedArity(1),\n },\n 'push-cols': {\n evaluate: ([grid, ...cols], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertGrid(cols, sourceCodeInfo)\n if (grid.length !== cols[0]!.length) {\n throw new LitsError(`All columns must have the same length as the number of rows in grid, but got ${cols.length}`, sourceCodeInfo)\n }\n\n const result: Any[][] = []\n\n for (let i = 0; i < grid.length; i += 1) {\n const row: Any[] = []\n row.push(...grid[i]!)\n cols.forEach((col) => {\n row.push(col[i]!)\n })\n result.push(row)\n }\n return result\n },\n arity: { min: 2 },\n },\n 'unshift-cols': {\n evaluate: ([grid, ...cols], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertGrid(cols, sourceCodeInfo)\n if (grid.length !== cols[0]!.length) {\n throw new LitsError(`All columns must have the same length as the number of rows in grid, but got ${cols.length}`, sourceCodeInfo)\n }\n\n const result: Any[][] = []\n\n for (let i = 0; i < grid.length; i += 1) {\n const row: Any[] = []\n cols.forEach((col) => {\n row.push(col[i]!)\n })\n row.push(...grid[i]!)\n result.push(row)\n }\n return result\n },\n arity: { min: 2 },\n },\n 'pop-col': {\n evaluate: ([grid], sourceCodeInfo): Any[][] | null => {\n assertGrid(grid, sourceCodeInfo)\n if (grid[0]!.length === 1) {\n return null\n }\n return grid.map(row => row.slice(0, -1))\n },\n arity: toFixedArity(1),\n },\n 'shift-col': {\n evaluate: ([grid], sourceCodeInfo): Any[][] | null => {\n assertGrid(grid, sourceCodeInfo)\n if (grid[0]!.length === 1) {\n return null\n }\n return grid.map(row => row.slice(1))\n },\n arity: toFixedArity(1),\n },\n 'from-array': {\n evaluate: ([array, rows], sourceCodeInfo): unknown[][] => {\n assertArray(array, sourceCodeInfo)\n assertNumber(rows, sourceCodeInfo, { integer: true, positive: true })\n if (array.length % rows !== 0) {\n throw new LitsError(`The number of elements in the array must be divisible by rows, but got ${array.length} and ${rows}`, sourceCodeInfo)\n }\n return fromArray(array, rows)\n },\n arity: toFixedArity(2),\n },\n}\n\n/**\n * The grid module containing 2D array manipulation functions.\n */\nfor (const [key, docs] of Object.entries(moduleDocs)) {\n if (gridFunctions[key])\n gridFunctions[key].docs = docs\n}\n\nexport const gridModule: LitsModule = {\n name: 'grid',\n functions: gridFunctions,\n}\n","/**\n * Creates a grid from a flat array with specified dimensions\n *\n * @param flatArray The flat array of values\n * @param rows Number of rows in the resulting grid\n * @returns A 2D array representing the grid\n */\nexport function fromArray(flatArray: unknown[], rows: number): unknown[][] {\n // Create the grid\n const grid: unknown[][] = []\n const cols = flatArray.length / rows\n // Reshape the flat array into rows and columns\n for (let i = 0; i < rows; i++) {\n const start = i * cols\n const end = start + cols\n grid.push(flatArray.slice(start, end))\n }\n\n return grid\n}\n"],"names":["getCodeMarker","sourceCodeInfo","position","code","leftPadding","column","rightPadding","length","repeat","Math","max","LitsError","Error","shortMessage","constructor","err","message","super","location","line","filePath","getLitsErrorMessage","this","Object","setPrototypeOf","prototype","name","NodeTypes","Number","String","NormalExpression","SpecialExpression","UserDefinedSymbol","NormalBuiltinSymbol","SpecialBuiltinSymbol","ReservedSymbol","Binding","Spread","NodeTypesSet","Set","values","functionTypeSet","FUNCTION_SYMBOL","REGEXP_SYMBOL","isLitsFunction","func","type","functionType","has","isNode","value","Array","isArray","valueToString","keys","find","key","RegExp","toString","JSON","stringify","getSourceCodeInfo","anyValue","isNumber","options","isNaN","integer","isInteger","finite","isFinite","zero","nonZero","positive","negative","nonPositive","nonNegative","gt","gte","lt","lte","assertNumber","sign","getSignString","numberType","range","getRangeString","filter","x","join","getNumberTypeName","annotatedArrays","WeakSet","vectors","notVectors","grids","notGrids","assertVector","vector","every","elem","add","isVector","assertGrid","grid","nbrOfCols","row","slice","isGrid","getAssertionError","typeName","assertArray","asAny","assertAny","undefined","isAny","isObj","regexp","isColl","isSeq","assertFunctionLike","isFunctionLike","toFixedArity","arity","min","moduleDocs","category","description","returns","args","a","b","variants","argumentNames","examples","seeAlso","col","shape","g","fill","rows","cols","generate","fn","reshape","transpose","rotate","begin","stop","hideOperatorForm","deleteCount","items","rest","map","mapi","reduce","reducei","result","i","j","push","gridFunctions","evaluate","predicate","contextStack","executeFunction","cell","transposed","generator","flatTable","flat","reverse","times","height","width","y","start","end","rowStart","colStart","rowEnd","colEnd","trMatrix","rowDeleteCount","colDeleteCount","params","forEach","asFunctionLike","at","initialValue","accumulator","array","flatArray","fromArray","docs","entries","gridModule","functions"],"mappings":"AAEM,SAAUA,EAAcC,GAC5B,IAAKA,EAAeC,WAAaD,EAAeE,KAC9C,MAAO,GAET,MAAMC,EAAcH,EAAeC,SAASG,OAAS,EAC/CC,EAAeL,EAAeE,KAAKI,OAASH,EAAc,EAChE,MAAO,GAAG,IAAII,OAAOC,KAAKC,IAAIN,EAAa,OAAO,IAAII,OAAOC,KAAKC,IAAIJ,EAAc,KACtF,CCkBM,MAAOK,UAAkBC,MACbX,eACAY,aAChB,WAAAC,CAAYC,EAAcd,GACxB,MAAMe,EAAUD,aAAeH,MAC3BG,EAAIC,QACJ,GAAGD,IAEPE,MA/BJ,SAA6BD,EAAiBf,GAC5C,IAAKA,EACH,OAAOe,EAET,MAAME,EAAW,GAAGjB,EAAeC,SAASiB,QAAQlB,EAAeC,SAASG,SAM5E,MAAO,GAAGW,IALWf,EAAemB,SAChC,KAAKnB,EAAemB,YAAYF,IAChC,cAAcA,QACIjB,EAAeE,SACbH,EAAcC,IAExC,CAoBUoB,CAAoBL,EAASf,IACnCqB,KAAKT,aAAeG,EACpBM,KAAKrB,eAAiBA,EACtBsB,OAAOC,eAAeF,KAAMX,EAAUc,WACtCH,KAAKI,KAAO,WACb,CAEM,aAAA1B,GACL,OAAOsB,KAAKrB,gBAAkBD,EAAcsB,KAAKrB,eAClD,EC5CI,MAAM0B,EAAY,CACvBC,OAAQ,EACRC,OAAQ,EACRC,iBAAkB,EAClBC,kBAAmB,EACnBC,kBAAmB,EACnBC,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,CACZwC,SAAU,EAAE6B,EAAOnD,GAAO1I,KAGxB,GAFA6G,EAAYgF,EAAO7L,GACnB+E,EAAa2D,EAAM1I,EAAgB,CAAEiE,SAAS,EAAMM,UAAU,IAC1DsH,EAAMvL,OAASoI,IAAS,EAC1B,MAAM,IAAIhI,EAAU,0EAA0EmL,EAAMvL,cAAcoI,IAAQ1I,GAE5H,OChoBU,SAAU8L,EAAsBpD,GAE9C,MAAMpC,EAAoB,GACpBqC,EAAOmD,EAAUxL,OAASoI,EAEhC,IAAK,IAAIkB,EAAI,EAAGA,EAAIlB,EAAMkB,IAAK,CAC7B,MAAMkB,EAAQlB,EAAIjB,EACZoC,EAAMD,EAAQnC,EACpBrC,EAAKwD,KAAKgC,EAAUrF,MAAMqE,EAAOC,GAClC,CAED,OAAOzE,CACT,CDonBayF,CAAUF,EAAOnD,IAE1BjB,MAAOD,EAAa,KAOxB,IAAK,MAAOjE,EAAKyI,KAAS1K,OAAO2K,QAAQtE,GACnCoC,EAAcxG,KAChBwG,EAAcxG,GAAKyI,KAAOA,GAGjB,MAAAE,EAAyB,CACpCzK,KAAM,OACN0K,UAAWpC"}
1
+ {"version":3,"file":"grid.esm.js","sources":["../../src/utils/debug/getCodeMarker.ts","../../src/errors.ts","../../src/constants/constants.ts","../../src/utils/symbols.ts","../../src/utils/debug/debugTools.ts","../../src/utils/debug/getSourceCodeInfo.ts","../../src/typeGuards/number.ts","../../src/typeGuards/annotatedArrays.ts","../../src/utils/getAssertionError.ts","../../src/typeGuards/array.ts","../../src/typeGuards/litsFunction.ts","../../src/typeGuards/lits.ts","../../src/utils/arity.ts","../../src/utils/maybePromise.ts","../../src/builtin/modules/grid/docs.ts","../../src/builtin/modules/grid/transpose.ts","../../src/builtin/modules/grid/index.ts","../../src/builtin/modules/grid/fromArray.ts"],"sourcesContent":["import type { SourceCodeInfo } from '../../tokenizer/token'\n\nexport function getCodeMarker(sourceCodeInfo: SourceCodeInfo): string {\n if (!sourceCodeInfo.position || !sourceCodeInfo.code)\n return ''\n\n const leftPadding = sourceCodeInfo.position.column - 1\n const rightPadding = sourceCodeInfo.code.length - leftPadding - 1\n return `${' '.repeat(Math.max(leftPadding, 0))}^${' '.repeat(Math.max(rightPadding, 0))}`\n}\n","import { getCodeMarker } from '../src/utils/debug/getCodeMarker'\nimport type { Arr } from './interface'\nimport type { SourceCodeInfo } from './tokenizer/token'\n\nfunction getLitsErrorMessage(message: string, sourceCodeInfo?: SourceCodeInfo) {\n if (!sourceCodeInfo) {\n return message\n }\n const location = `${sourceCodeInfo.position.line}:${sourceCodeInfo.position.column}`\n const filePathLine = sourceCodeInfo.filePath\n ? `\\n${sourceCodeInfo.filePath}:${location}`\n : `\\nLocation ${location}`\n const codeLine = `\\n${sourceCodeInfo.code}`\n const codeMarker = `\\n${getCodeMarker(sourceCodeInfo)}`\n return `${message}${filePathLine}${codeLine}${codeMarker}`\n}\n\nexport class RecurSignal extends Error {\n public params: Arr\n constructor(params: Arr) {\n super(`recur, params: ${params}`)\n Object.setPrototypeOf(this, RecurSignal.prototype)\n this.name = 'RecurSignal'\n this.params = params\n }\n}\n\nexport class LitsError extends Error {\n public readonly sourceCodeInfo?: SourceCodeInfo\n public readonly shortMessage: string\n constructor(err: unknown, sourceCodeInfo: SourceCodeInfo | undefined) {\n const message = err instanceof Error\n ? err.message\n : `${err}`\n\n super(getLitsErrorMessage(message, sourceCodeInfo))\n this.shortMessage = message\n this.sourceCodeInfo = sourceCodeInfo\n Object.setPrototypeOf(this, LitsError.prototype)\n this.name = 'LitsError'\n }\n\n public getCodeMarker(): string | undefined {\n return this.sourceCodeInfo && getCodeMarker(this.sourceCodeInfo)\n }\n}\n\nexport class UserDefinedError extends LitsError {\n public userMessage: string\n constructor(message: string, sourceCodeInfo?: SourceCodeInfo) {\n super(message, sourceCodeInfo)\n this.userMessage = message\n Object.setPrototypeOf(this, UserDefinedError.prototype)\n this.name = 'UserDefinedError'\n }\n}\n\nexport class AssertionError extends LitsError {\n constructor(message: string | Error, sourceCodeInfo?: SourceCodeInfo) {\n super(message, sourceCodeInfo)\n Object.setPrototypeOf(this, AssertionError.prototype)\n this.name = 'AssertionError'\n }\n}\n\nexport class UndefinedSymbolError extends LitsError {\n public symbol: string\n constructor(symbolName: string, sourceCodeInfo?: SourceCodeInfo) {\n const message = `Undefined symbol '${symbolName}'.`\n super(message, sourceCodeInfo)\n this.symbol = symbolName\n Object.setPrototypeOf(this, UndefinedSymbolError.prototype)\n this.name = 'UndefinedSymbolError'\n }\n}\n\nexport function isLitsError(error: unknown): error is LitsError {\n return error instanceof LitsError\n}\n","export const NodeTypes = {\n Number: 1,\n String: 2,\n NormalExpression: 3,\n SpecialExpression: 4,\n UserDefinedSymbol: 5,\n NormalBuiltinSymbol: 6,\n SpecialBuiltinSymbol: 7,\n ReservedSymbol: 8,\n Binding: 9,\n Spread: 10,\n} as const\n\nconst NodeTypesSet = new Set(Object.values(NodeTypes))\n\nexport type NodeType = typeof NodeTypes[keyof typeof NodeTypes]\n\nexport function getNodeTypeName(type: NodeType): keyof typeof NodeTypes {\n return Object.keys(NodeTypes).find(key => NodeTypes[key as keyof typeof NodeTypes] === type) as keyof typeof NodeTypes\n}\n\n// TODO, is this needed?\nexport function isNodeType(type: unknown): type is NodeType {\n return typeof type === 'number' && NodeTypesSet.has(type as NodeType)\n}\n\nconst functionTypes = [\n 'UserDefined',\n 'Partial',\n 'Comp',\n 'Constantly',\n 'Juxt',\n 'Complement',\n 'EveryPred',\n 'SomePred',\n 'Fnull',\n 'Builtin',\n 'SpecialBuiltin',\n 'NativeJsFunction',\n 'Module',\n] as const\n\nconst functionTypeSet = new Set(functionTypes)\n\nexport type FunctionType = typeof functionTypes[number]\n\nexport function isFunctionType(type: unknown): type is FunctionType {\n return typeof type === 'string' && functionTypeSet.has(type as FunctionType)\n}\n","export const FUNCTION_SYMBOL = '^^fn^^'\nexport const REGEXP_SYMBOL = '^^re^^'\n","import { getNodeTypeName, isFunctionType, isNodeType } from '../../constants/constants'\nimport type { AstNode, LitsFunction } from '../../parser/types'\nimport { FUNCTION_SYMBOL } from '../symbols'\n\nfunction isLitsFunction(func: unknown): func is LitsFunction {\n if (func === null || typeof func !== 'object')\n return false\n\n return FUNCTION_SYMBOL in func && 'functionType' in func && isFunctionType(func.functionType)\n}\n\nfunction isNode(value: unknown): value is AstNode {\n if (!Array.isArray(value) || value.length < 2)\n return false\n return isNodeType(value[0])\n}\n\nexport function valueToString(value: unknown): string {\n if (isLitsFunction(value))\n // eslint-disable-next-line ts/no-unsafe-member-access\n return `<function ${(value as any).name || '\\u03BB'}>`\n\n if (isNode(value))\n return `${getNodeTypeName(value[0])}-node`\n\n if (value === null)\n return 'null'\n\n if (typeof value === 'object' && value instanceof RegExp)\n return `${value}`\n\n if (typeof value === 'object' && value instanceof Error)\n return value.toString()\n\n return JSON.stringify(value)\n}\n","import type { SourceCodeInfo } from '../../tokenizer/token'\n\nexport function getSourceCodeInfo(anyValue: any, sourceCodeInfo: SourceCodeInfo | undefined): SourceCodeInfo | undefined {\n // eslint-disable-next-line ts/no-unsafe-return, ts/no-unsafe-member-access\n return anyValue?.sourceCodeInfo ?? sourceCodeInfo\n}\n","import { LitsError } from '../errors'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { valueToString } from '../utils/debug/debugTools'\nimport { getSourceCodeInfo } from '../utils/debug/getSourceCodeInfo'\n\ntype SignOptions =\n | {\n positive?: true\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: true\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: true\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: true\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: true\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: true\n }\n\ntype GtOptions =\n | {\n gt?: number\n gte?: never\n }\n | {\n gt?: never\n gte?: number\n }\n\ntype LtOptions =\n | {\n lt?: number\n lte?: never\n }\n | {\n lt?: never\n lte?: number\n }\n\ntype NumberOptions = {\n integer?: true\n finite?: true\n} & SignOptions &\nGtOptions &\nLtOptions\n\nfunction getRangeString(options: NumberOptions): string {\n const hasUpperAndLowerBound\n = (typeof options.gt === 'number' || typeof options.gte === 'number')\n && (typeof options.lt === 'number' || typeof options.lte === 'number')\n if (hasUpperAndLowerBound) {\n return `${typeof options.gt === 'number' ? `${options.gt} < n ` : `${options.gte} <= n `}${\n typeof options.lt === 'number' ? `< ${options.lt}` : `<= ${options.lte}`\n }`\n }\n else if (typeof options.gt === 'number' || typeof options.gte === 'number') {\n return `${typeof options.gt === 'number' ? `n > ${options.gt}` : `n >= ${options.gte}`}`\n }\n else if (typeof options.lt === 'number' || typeof options.lte === 'number') {\n return `${typeof options.lt === 'number' ? `n < ${options.lt}` : `n <= ${options.lte}`}`\n }\n else { return '' }\n}\n\nfunction getSignString(options: NumberOptions): string {\n return options.positive\n ? 'positive'\n : options.negative\n ? 'negative'\n : options.nonNegative\n ? 'non negative'\n : options.nonPositive\n ? 'non positive'\n : options.nonZero\n ? 'non zero'\n : ''\n}\n\nfunction getNumberTypeName(options: NumberOptions): string {\n if (options.zero)\n return 'zero'\n\n const sign = getSignString(options)\n const numberType = options.integer ? 'integer' : 'number'\n const finite = options.finite ? 'finite' : ''\n const range = getRangeString(options)\n\n return [sign, finite, numberType, range].filter(x => !!x).join(' ')\n}\n\nexport function isNumber(value: unknown, options: NumberOptions = {}): value is number {\n if (typeof value !== 'number')\n return false\n\n if (Number.isNaN(value))\n return false\n\n if (options.integer && !Number.isInteger(value))\n return false\n\n if (options.finite && !Number.isFinite(value))\n return false\n\n if (options.zero && value !== 0)\n return false\n\n if (options.nonZero && value === 0)\n return false\n\n if (options.positive && value <= 0)\n return false\n\n if (options.negative && value >= 0)\n return false\n\n if (options.nonPositive && value > 0)\n return false\n\n if (options.nonNegative && value < 0)\n return false\n\n if (typeof options.gt === 'number' && value <= options.gt)\n return false\n\n if (typeof options.gte === 'number' && value < options.gte)\n return false\n\n if (typeof options.lt === 'number' && value >= options.lt)\n return false\n\n if (typeof options.lte === 'number' && value > options.lte)\n return false\n\n return true\n}\n\nexport function assertNumber(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n options: NumberOptions = {},\n): asserts value is number {\n if (!isNumber(value, options)) {\n throw new LitsError(\n `Expected ${getNumberTypeName(options)}, got ${valueToString(value)}.`,\n getSourceCodeInfo(value, sourceCodeInfo),\n )\n }\n}\n\nexport function asNumber(\n value: unknown,\n sourceCodeInfo: SourceCodeInfo | undefined,\n options: NumberOptions = {},\n): number {\n assertNumber(value, sourceCodeInfo, options)\n return value\n}\n","import { LitsError } from '../errors'\nimport type { Any } from '../interface'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { isNumber } from './number'\n\nconst annotatedArrays = new WeakSet<unknown[]>()\nconst vectors = new WeakSet<unknown[]>()\nconst notVectors = new WeakSet<unknown[]>()\nconst matrices = new WeakSet<unknown[]>()\nconst notMatrices = new WeakSet<unknown[]>()\nconst grids = new WeakSet<unknown[]>()\nconst notGrids = new WeakSet<unknown[]>()\n\nexport function annotate<T>(value: T): T {\n if (!Array.isArray(value)) {\n return value\n }\n if (annotatedArrays.has(value)) {\n return value\n }\n isVector(value)\n if (!isMatrix(value)) {\n isGrid(value)\n }\n\n return value\n}\nexport function isVector(vector: unknown): vector is number[] {\n if (!Array.isArray(vector)) {\n return false\n }\n\n if (vectors.has(vector)) {\n return true\n }\n if (notVectors.has(vector)) {\n return false\n }\n\n if (vector.every(elem => isNumber(elem))) {\n annotatedArrays.add(vector)\n vectors.add(vector)\n return true\n }\n notVectors.add(vector)\n return false\n}\n\nexport function assertVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is number[] {\n if (!isVector(vector)) {\n throw new LitsError(`Expected a vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function is2dVector(vector: unknown): vector is [number, number] {\n if (!isVector(vector)) {\n return false\n }\n return vector.length === 2\n}\nexport function assert2dVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is [number, number] {\n if (!is2dVector(vector)) {\n throw new LitsError(`Expected a 2d vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function is3dVector(vector: unknown): vector is [number, number, number] {\n if (!isVector(vector)) {\n return false\n }\n return vector.length === 3\n}\nexport function assert3dVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is [number, number, number] {\n if (!is3dVector(vector)) {\n throw new LitsError(`Expected a 3d vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function assertNonEmptyVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is number[] {\n assertVector(vector, sourceCodeInfo)\n if (vector.length === 0) {\n throw new LitsError(`Expected a non empty vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function isGrid(grid: unknown): grid is unknown[][] {\n if (!Array.isArray(grid)) {\n return false\n }\n if (grids.has(grid)) {\n return true\n }\n if (notGrids.has(grid)) {\n return false\n }\n if (grid.length === 0) {\n notGrids.add(grid)\n return false\n }\n if (!Array.isArray(grid[0])) {\n notGrids.add(grid)\n return false\n }\n const nbrOfCols = grid[0].length\n for (const row of grid.slice(1)) {\n if (!Array.isArray(row)) {\n notGrids.add(grid)\n return false\n }\n if (row.length !== nbrOfCols) {\n notGrids.add(grid)\n return false\n }\n }\n annotatedArrays.add(grid)\n grids.add(grid)\n return true\n}\n\nexport function assertGrid(grid: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts grid is Any[][] {\n if (!isGrid(grid)) {\n throw new LitsError(`Expected a grid, but got ${grid}`, sourceCodeInfo)\n }\n}\n\nexport function isMatrix(matrix: unknown): matrix is number[][] {\n if (!Array.isArray(matrix)) {\n return false\n }\n if (matrices.has(matrix)) {\n return true\n }\n if (notMatrices.has(matrix)) {\n return false\n }\n if (matrix.length === 0) {\n notMatrices.add(matrix)\n return false\n }\n if (!Array.isArray(matrix[0]) || matrix[0].length === 0) {\n notMatrices.add(matrix)\n return false\n }\n const nbrOfCols = matrix[0].length\n for (const row of matrix) {\n if (!Array.isArray(row) || row.length !== nbrOfCols || row.some(cell => !isNumber(cell))) {\n notMatrices.add(matrix)\n return false\n }\n }\n annotatedArrays.add(matrix)\n grids.add(matrix)\n matrices.add(matrix)\n return true\n}\n\nexport function assertMatrix(matrix: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts matrix is number[][] {\n if (!isMatrix(matrix)) {\n throw new LitsError(`Expected a matrix, but got ${matrix}`, sourceCodeInfo)\n }\n}\n\nexport function assertSquareMatrix(matrix: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts matrix is number[][] {\n if (!isMatrix(matrix)) {\n throw new LitsError(`Expected a matrix, but got ${matrix}`, sourceCodeInfo)\n }\n if (matrix.length !== matrix[0]!.length) {\n throw new LitsError(`Expected square matrix, but got ${matrix.length} and ${matrix[0]!.length}`, sourceCodeInfo)\n }\n}\n\nexport function isSquareMatrix(matrix: unknown): matrix is number[][] {\n if (!isMatrix(matrix)) {\n return false\n }\n if (matrix.length !== matrix[0]!.length) {\n return false\n }\n return true\n}\n","import { LitsError } from '../errors'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { valueToString } from './debug/debugTools'\nimport { getSourceCodeInfo } from './debug/getSourceCodeInfo'\n\nexport function getAssertionError(typeName: string, value: unknown, sourceCodeInfo?: SourceCodeInfo): LitsError {\n return new LitsError(`Expected ${typeName}, got ${valueToString(value)}.`, getSourceCodeInfo(value, sourceCodeInfo))\n}\n","import type { SourceCodeInfo } from '../tokenizer/token'\nimport { getAssertionError } from '../utils/getAssertionError'\n\n// isArray not needed, use Array.isArary\nexport function asArray(value: unknown, sourceCodeInfo?: SourceCodeInfo): unknown[] {\n assertArray(value, sourceCodeInfo)\n return value\n}\nexport function assertArray(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is unknown[] {\n if (!Array.isArray(value))\n throw getAssertionError('array', value, sourceCodeInfo)\n}\n\nexport function isStringArray(value: unknown): value is string[] {\n return Array.isArray(value) && value.every(v => typeof v === 'string')\n}\nexport function asStringArray(value: unknown, sourceCodeInfo?: SourceCodeInfo): string[] {\n assertStringArray(value, sourceCodeInfo)\n return value\n}\nexport function assertStringArray(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is string[] {\n if (!isStringArray(value))\n throw getAssertionError('array of strings', value, sourceCodeInfo)\n}\n\nexport function isCharArray(value: unknown): value is string[] {\n return Array.isArray(value) && value.every(v => typeof v === 'string' && v.length === 1)\n}\nexport function asCharArray(value: unknown, sourceCodeInfo?: SourceCodeInfo): string[] {\n assertCharArray(value, sourceCodeInfo)\n return value\n}\nexport function assertCharArray(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is string[] {\n if (!isCharArray(value))\n throw getAssertionError('array of strings', value, sourceCodeInfo)\n}\n","import type { LitsFunction, NativeJsFunction, NormalBuiltinFunction, UserDefinedFunction } from '../parser/types'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { getAssertionError } from '../utils/getAssertionError'\nimport { FUNCTION_SYMBOL } from '../utils/symbols'\nimport { isUnknownRecord } from '.'\n\nexport function isLitsFunction(value: unknown): value is LitsFunction {\n if (value === null || typeof value !== 'object')\n return false\n\n return !!(value as LitsFunction)[FUNCTION_SYMBOL]\n}\nexport function asLitsFunction(value: unknown, sourceCodeInfo?: SourceCodeInfo): LitsFunction {\n assertLitsFunction(value, sourceCodeInfo)\n return value\n}\nexport function assertLitsFunction(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is LitsFunction {\n if (!isLitsFunction(value))\n throw getAssertionError('LitsFunction', value, sourceCodeInfo)\n}\n\nexport function isUserDefinedFunction(value: unknown): value is UserDefinedFunction {\n return isLitsFunction(value) && value.functionType === 'UserDefined'\n}\nexport function asUserDefinedFunction(value: unknown, sourceCodeInfo?: SourceCodeInfo): UserDefinedFunction {\n assertUserDefinedFunction(value, sourceCodeInfo)\n return value\n}\nexport function assertUserDefinedFunction(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n): asserts value is UserDefinedFunction {\n if (!isUserDefinedFunction(value))\n throw getAssertionError('NativeJsFunction', value, sourceCodeInfo)\n}\n\nexport function isNativeJsFunction(value: unknown): value is NativeJsFunction {\n return isLitsFunction(value) && value.functionType === 'NativeJsFunction'\n}\nexport function asNativeJsFunction(value: unknown, sourceCodeInfo?: SourceCodeInfo): NativeJsFunction {\n assertNativeJsFunction(value, sourceCodeInfo)\n return value\n}\nexport function assertNativeJsFunction(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n): asserts value is NativeJsFunction {\n if (!isNativeJsFunction(value))\n throw getAssertionError('NativeJsFunction', value, sourceCodeInfo)\n}\n\nexport function isBuiltinFunction(value: unknown): value is NormalBuiltinFunction {\n return isUnknownRecord(value) && value.functionType === 'Builtin'\n}\n","import type { Any, Coll, Obj, Seq } from '../interface'\nimport type { FunctionLike, RegularExpression } from '../parser/types'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { getAssertionError } from '../utils/getAssertionError'\nimport { REGEXP_SYMBOL } from '../utils/symbols'\nimport { isLitsFunction } from './litsFunction'\n\nexport function isAny(value: unknown): value is Any {\n // TODO weak test\n return value !== undefined\n}\nexport function asAny(value: unknown, sourceCodeInfo?: SourceCodeInfo): Any {\n assertAny(value, sourceCodeInfo)\n return value\n}\nexport function assertAny(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is Any {\n if (!isAny(value))\n throw getAssertionError('not undefined', value, sourceCodeInfo)\n}\n\nexport function isSeq(value: unknown): value is Seq {\n return Array.isArray(value) || typeof value === 'string'\n}\nexport function asSeq(value: unknown, sourceCodeInfo?: SourceCodeInfo): Seq {\n assertSeq(value, sourceCodeInfo)\n return value\n}\nexport function assertSeq(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is Seq {\n if (!isSeq(value))\n throw getAssertionError('string or array', value, sourceCodeInfo)\n}\n\nexport function isObj(value: unknown): value is Obj {\n return !(\n value === null\n || typeof value !== 'object'\n || Array.isArray(value)\n || value instanceof RegExp\n || isLitsFunction(value)\n || isRegularExpression(value)\n )\n}\nexport function asObj(value: unknown, sourceCodeInfo?: SourceCodeInfo): Obj {\n assertObj(value, sourceCodeInfo)\n return value\n}\nexport function assertObj(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is Obj {\n if (!isObj(value))\n throw getAssertionError('object', value, sourceCodeInfo)\n}\n\nexport function isColl(value: unknown): value is Coll {\n return isSeq(value) || isObj(value)\n}\nexport function asColl(value: unknown, sourceCodeInfo?: SourceCodeInfo): Coll {\n assertColl(value, sourceCodeInfo)\n return value\n}\nexport function assertColl(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is Coll {\n if (!isColl(value))\n throw getAssertionError('string, array or object', value, sourceCodeInfo)\n}\n\nexport function isRegularExpression(regexp: unknown): regexp is RegularExpression {\n if (regexp === null || typeof regexp !== 'object')\n return false\n\n return !!(regexp as RegularExpression)[REGEXP_SYMBOL]\n}\nexport function asRegularExpression(value: unknown, sourceCodeInfo?: SourceCodeInfo): RegularExpression {\n assertRegularExpression(value, sourceCodeInfo)\n return value\n}\nexport function assertRegularExpression(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n): asserts value is RegularExpression {\n if (!isRegularExpression(value))\n throw getAssertionError('RegularExpression', value, sourceCodeInfo)\n}\n\nexport function isStringOrRegularExpression(value: unknown): value is string | RegularExpression {\n return isRegularExpression(value) || typeof value === 'string'\n}\nexport function asStringOrRegularExpression(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n): string | RegularExpression {\n assertStringOrRegularExpression(value, sourceCodeInfo)\n return value\n}\nexport function assertStringOrRegularExpression(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n): asserts value is string | RegularExpression {\n if (!isStringOrRegularExpression(value))\n throw getAssertionError('string or RegularExpression', value, sourceCodeInfo)\n}\n\nfunction isFunctionLike(value: unknown): value is FunctionLike {\n if (typeof value === 'number')\n return true\n if (isColl(value))\n return true\n if (isLitsFunction(value))\n return true\n\n return false\n}\nexport function asFunctionLike(value: unknown, sourceCodeInfo?: SourceCodeInfo): FunctionLike {\n assertFunctionLike(value, sourceCodeInfo)\n return value\n}\nexport function assertFunctionLike(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is FunctionLike {\n if (!isFunctionLike(value))\n throw getAssertionError('FunctionLike', value, sourceCodeInfo)\n}\n","import type { Arity } from '../builtin/interface'\nimport { LitsError } from '../errors'\nimport type { FunctionLike } from '../parser/types'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { isColl } from '../typeGuards/lits'\nimport { valueToString } from './debug/debugTools'\n\nexport function arityAccepts(arity: Arity, nbrOfParams: number): boolean {\n const { min, max } = arity\n if (typeof min === 'number' && nbrOfParams < min) {\n return false\n }\n if (typeof max === 'number' && nbrOfParams > max) {\n return false\n }\n return true\n}\n\nexport function arityAcceptsMin(arity: Arity, nbrOfParams: number): boolean {\n const { min } = arity\n if (typeof min === 'number' && nbrOfParams < min) {\n return false\n }\n return true\n}\n\nexport function getCommonArityFromFunctions(params: FunctionLike[]): Arity | null {\n return params.reduce((acc: Arity | null, param): Arity | null => {\n if (acc === null) {\n return null\n }\n const arity: Arity = (typeof param === 'number' || isColl(param)) ? toFixedArity(1) : param.arity\n const { min: aMin, max: aMax } = arity\n const { min: bMin, max: bMax } = acc\n const min = typeof aMin === 'number' && typeof bMin === 'number'\n ? Math.max(aMin, bMin)\n : typeof aMin === 'number' ? aMin : typeof bMin === 'number' ? bMin : undefined\n const max = typeof aMax === 'number' && typeof bMax === 'number'\n ? Math.min(aMax, bMax)\n : typeof aMax === 'number' ? aMax : typeof bMax === 'number' ? bMax : undefined\n\n if (typeof min === 'number' && typeof max === 'number' && min > max) {\n return null\n }\n\n return { min, max }\n }, {})\n}\n\nexport function getArityFromFunction(param: FunctionLike): Arity {\n return (typeof param === 'number' || isColl(param)) ? toFixedArity(1) : param.arity\n}\n\nexport function assertNumberOfParams(arity: Arity, length: number, sourceCodeInfo: SourceCodeInfo | undefined): void {\n const { min, max } = arity\n if (typeof min === 'number' && length < min) {\n throw new LitsError(\n `Wrong number of arguments, expected at least ${min}, got ${valueToString(length)}.`,\n sourceCodeInfo,\n )\n }\n\n if (typeof max === 'number' && length > max) {\n throw new LitsError(\n `Wrong number of arguments, expected at most ${max}, got ${valueToString(length)}.`,\n sourceCodeInfo,\n )\n }\n}\n\nexport function canBeOperator(count: Arity): boolean {\n if (typeof count.max === 'number' && count.max < 2) {\n return false\n }\n\n if (typeof count.min === 'number' && count.min > 2) {\n return false\n }\n\n return true\n}\n\nexport function toFixedArity(arity: number): Arity {\n return { min: arity, max: arity }\n}\n","/**\n * MaybePromise utilities for transparent async support.\n *\n * The sync path stays zero-overhead — when no async JS functions are involved,\n * everything runs synchronously with only `instanceof Promise` checks as overhead.\n * When an async value is detected, the evaluation chain switches to Promise-based\n * execution for the remainder.\n */\n\nexport type MaybePromise<T> = T | Promise<T>\n\n/**\n * Chain a value that might be a Promise. If the value is sync, calls fn synchronously.\n * If it's a Promise, chains with .then().\n */\nexport function chain<T, U>(value: MaybePromise<T>, fn: (v: T) => MaybePromise<U>): MaybePromise<U> {\n if (value instanceof Promise) {\n return value.then(fn)\n }\n return fn(value)\n}\n\n/**\n * Like Array.map but handles MaybePromise callbacks sequentially.\n * In the sync case, runs as a simple loop. Switches to async only when needed.\n */\nexport function mapSequential<T, U>(\n arr: readonly T[],\n fn: (elem: T, index: number) => MaybePromise<U>,\n): MaybePromise<U[]> {\n const results: U[] = []\n for (let i = 0; i < arr.length; i++) {\n const result = fn(arr[i]!, i)\n if (result instanceof Promise) {\n return chainRemainingMap(result, results, arr, fn, i)\n }\n results.push(result)\n }\n return results\n}\n\nasync function chainRemainingMap<T, U>(\n currentPromise: Promise<U>,\n results: U[],\n arr: readonly T[],\n fn: (elem: T, index: number) => MaybePromise<U>,\n startIndex: number,\n): Promise<U[]> {\n results.push(await currentPromise)\n for (let i = startIndex + 1; i < arr.length; i++) {\n results.push(await fn(arr[i]!, i))\n }\n return results\n}\n\n/**\n * Like Array.reduce but handles MaybePromise callbacks sequentially.\n * In the sync case, runs as a simple loop. Switches to async only when needed.\n */\nexport function reduceSequential<T, U>(\n arr: readonly T[],\n fn: (acc: U, elem: T, index: number) => MaybePromise<U>,\n initial: U,\n): MaybePromise<U> {\n let result: U = initial\n for (let i = 0; i < arr.length; i++) {\n const next = fn(result, arr[i]!, i)\n if (next instanceof Promise) {\n return chainRemainingReduce(next, arr, fn, i)\n }\n result = next\n }\n return result\n}\n\nasync function chainRemainingReduce<T, U>(\n currentPromise: Promise<U>,\n arr: readonly T[],\n fn: (acc: U, elem: T, index: number) => MaybePromise<U>,\n startIndex: number,\n): Promise<U> {\n let result = await currentPromise\n for (let i = startIndex + 1; i < arr.length; i++) {\n result = await fn(result, arr[i]!, i)\n }\n return result\n}\n\n/**\n * Like Array.forEach but handles MaybePromise callbacks sequentially.\n * In the sync case, runs as a simple loop. Switches to async only when needed.\n */\nexport function forEachSequential<T>(\n arr: readonly T[],\n fn: (elem: T, index: number) => MaybePromise<void>,\n): MaybePromise<void> {\n for (let i = 0; i < arr.length; i++) {\n const result = fn(arr[i]!, i)\n if (result instanceof Promise) {\n return chainRemainingForEach(result, arr, fn, i)\n }\n }\n}\n\nasync function chainRemainingForEach<T>(\n currentPromise: Promise<void>,\n arr: readonly T[],\n fn: (elem: T, index: number) => MaybePromise<void>,\n startIndex: number,\n): Promise<void> {\n await currentPromise\n for (let i = startIndex + 1; i < arr.length; i++) {\n await fn(arr[i]!, i)\n }\n}\n\n/**\n * Try/catch that handles MaybePromise values correctly.\n * If tryFn returns a Promise, catches both sync throws and Promise rejections.\n */\nexport function tryCatch<T>(\n tryFn: () => MaybePromise<T>,\n catchFn: (error: unknown) => MaybePromise<T>,\n): MaybePromise<T> {\n try {\n const result = tryFn()\n if (result instanceof Promise) {\n return result.catch(catchFn)\n }\n return result\n }\n catch (error) {\n return catchFn(error)\n }\n}\n\n/**\n * Like Array.some but handles MaybePromise callbacks sequentially.\n * Returns the first truthy MaybePromise result, or false.\n */\nexport function someSequential<T>(\n arr: readonly T[],\n fn: (elem: T, index: number) => MaybePromise<unknown>,\n): MaybePromise<boolean> {\n for (let i = 0; i < arr.length; i++) {\n const result = fn(arr[i]!, i)\n if (result instanceof Promise) {\n return chainRemainingSome(result, arr, fn, i)\n }\n if (result)\n return true\n }\n return false\n}\n\nasync function chainRemainingSome<T>(\n currentPromise: Promise<unknown>,\n arr: readonly T[],\n fn: (elem: T, index: number) => MaybePromise<unknown>,\n startIndex: number,\n): Promise<boolean> {\n if (await currentPromise)\n return true\n for (let i = startIndex + 1; i < arr.length; i++) {\n if (await fn(arr[i]!, i))\n return true\n }\n return false\n}\n\n/**\n * Like Array.every but handles MaybePromise callbacks sequentially.\n * Returns false as soon as a falsy result is found.\n */\nexport function everySequential<T>(\n arr: readonly T[],\n fn: (elem: T, index: number) => MaybePromise<unknown>,\n): MaybePromise<boolean> {\n for (let i = 0; i < arr.length; i++) {\n const result = fn(arr[i]!, i)\n if (result instanceof Promise) {\n return chainRemainingEvery(result, arr, fn, i)\n }\n if (!result)\n return false\n }\n return true\n}\n\nasync function chainRemainingEvery<T>(\n currentPromise: Promise<unknown>,\n arr: readonly T[],\n fn: (elem: T, index: number) => MaybePromise<unknown>,\n startIndex: number,\n): Promise<boolean> {\n if (!await currentPromise)\n return false\n for (let i = startIndex + 1; i < arr.length; i++) {\n if (!await fn(arr[i]!, i))\n return false\n }\n return true\n}\n\n/**\n * Like Array.filter but handles MaybePromise callbacks sequentially.\n * Returns the filtered array.\n */\nexport function filterSequential<T>(\n arr: readonly T[],\n fn: (elem: T, index: number) => MaybePromise<unknown>,\n): MaybePromise<T[]> {\n const results: T[] = []\n for (let i = 0; i < arr.length; i++) {\n const result = fn(arr[i]!, i)\n if (result instanceof Promise) {\n return chainRemainingFilter(result, results, arr, fn, i)\n }\n if (result)\n results.push(arr[i]!)\n }\n return results\n}\n\nasync function chainRemainingFilter<T>(\n currentPromise: Promise<unknown>,\n results: T[],\n arr: readonly T[],\n fn: (elem: T, index: number) => MaybePromise<unknown>,\n startIndex: number,\n): Promise<T[]> {\n if (await currentPromise)\n results.push(arr[startIndex]!)\n for (let i = startIndex + 1; i < arr.length; i++) {\n if (await fn(arr[i]!, i))\n results.push(arr[i]!)\n }\n return results\n}\n\n/**\n * Like Array.findIndex but handles MaybePromise callbacks sequentially.\n * Returns -1 if no element matches.\n */\nexport function findIndexSequential<T>(\n arr: readonly T[],\n fn: (elem: T, index: number) => MaybePromise<unknown>,\n): MaybePromise<number> {\n for (let i = 0; i < arr.length; i++) {\n const result = fn(arr[i]!, i)\n if (result instanceof Promise) {\n return chainRemainingFindIndex(result, arr, fn, i)\n }\n if (result)\n return i\n }\n return -1\n}\n\nasync function chainRemainingFindIndex<T>(\n currentPromise: Promise<unknown>,\n arr: readonly T[],\n fn: (elem: T, index: number) => MaybePromise<unknown>,\n startIndex: number,\n): Promise<number> {\n if (await currentPromise)\n return startIndex\n for (let i = startIndex + 1; i < arr.length; i++) {\n if (await fn(arr[i]!, i))\n return i\n }\n return -1\n}\n","import type { FunctionDocs } from '../../interface'\n\nexport const moduleDocs: Record<string, FunctionDocs> = {\n 'every?': {\n category: 'grid',\n 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.',\n returns: {\n type: 'boolean',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n '// 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?)',\n '// 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?)',\n '// 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?)',\n ],\n seeAlso: ['collection.every?', 'grid.some?', 'grid.every-row?', 'grid.every-col?'],\n },\n 'some?': {\n category: 'grid',\n 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.',\n returns: {\n type: 'boolean',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { some? } = import(\"grid\");\\nsome?([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], string?)',\n 'let { some? } = import(\"grid\");\\nsome?([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n], string?)',\n 'let { some? } = import(\"grid\");\\nsome?([\\n [1, 2],\\n [3, 4],\\n], string?)',\n ],\n seeAlso: ['collection.any?', 'grid.every?', 'grid.some-row?', 'grid.some-col?'],\n },\n 'every-row?': {\n category: 'grid',\n 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.',\n returns: {\n type: 'boolean',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { every-row? } = import(\"grid\");\\nevery-row?([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], -> string?($[0]))',\n 'let { every-row? } = import(\"grid\");\\nevery-row?([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n], -> string?($[0]))',\n 'let { every-row? } = import(\"grid\");\\nevery-row?([\\n [1, 2],\\n [3, 4],\\n], -> string?($[0]))',\n ],\n seeAlso: ['grid.some-row?', 'grid.every-col?', 'grid.every?'],\n },\n 'some-row?': {\n category: 'grid',\n 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.',\n returns: {\n type: 'boolean',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { some-row? } = import(\"grid\");\\nsome-row?([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], -> $ contains? \"Albert\")',\n 'let { some-row? } = import(\"grid\");\\nsome-row?([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n], -> $ contains? \"Albert\")',\n 'let { some-row? } = import(\"grid\");\\nsome-row?([\\n [1, 2],\\n [3, 4],\\n], -> $ contains? \"Albert\")',\n ],\n seeAlso: ['grid.every-row?', 'grid.some-col?', 'grid.some?'],\n },\n 'every-col?': {\n category: 'grid',\n 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.',\n returns: {\n type: 'boolean',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { every-col? } = import(\"grid\");\\nevery-col?([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], -> string?($[0]))',\n 'let { every-col? } = import(\"grid\");\\nevery-col?([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n], -> string?($[0]))',\n 'let { every-col? } = import(\"grid\");\\nevery-col?([\\n [1, 2],\\n [3, 4],\\n], -> string?($[0]))',\n ],\n seeAlso: ['grid.some-col?', 'grid.every-row?', 'grid.every?'],\n },\n 'some-col?': {\n category: 'grid',\n 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.',\n returns: {\n type: 'boolean',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { some-col? } = import(\"grid\");\\nsome-col?([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], -> $ contains? \"Albert\")',\n 'let { some-col? } = import(\"grid\");\\nsome-col?([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n], -> $ contains? \"Albert\")',\n 'let { some-col? } = import(\"grid\");\\nsome-col?([\\n [1, 2],\\n [3, 4],\\n], -> $ contains? \"Albert\")',\n ],\n seeAlso: ['grid.every-col?', 'grid.some-row?', 'grid.some?'],\n },\n 'row': {\n category: 'grid',\n description: 'Returns the row at index $a in the grid $b.',\n returns: {\n type: 'any',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'number',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { row } = import(\"grid\");\\nrow([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 0)',\n 'let { row } = import(\"grid\");\\nrow([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1)',\n 'let { row } = import(\"grid\");\\nrow([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 2)',\n ],\n seeAlso: ['grid.col', 'grid.shape'],\n },\n 'col': {\n category: 'grid',\n description: 'Returns the column at index $a in the grid $b.',\n returns: {\n type: 'any',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'number',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { col } = import(\"grid\");\\ncol([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 0)',\n 'let { col } = import(\"grid\");\\ncol([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1)',\n 'let { col } = import(\"grid\");\\ncol([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 2)',\n ],\n seeAlso: ['grid.row', 'grid.shape'],\n },\n 'shape': {\n category: 'grid',\n 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.',\n returns: {\n type: 'vector',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to get the shape of.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { shape } = import(\"grid\");\\nshape([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n 'let { shape } = import(\"grid\");\\nshape([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n])',\n 'let { shape } = import(\"grid\");\\nshape([\\n [1, 2],\\n [3, 4],\\n])',\n ],\n seeAlso: ['grid.row', 'grid.col', 'grid.reshape'],\n },\n 'fill': {\n category: 'grid',\n description: 'Creates a grid of the specified size, filled with the specified value.',\n returns: {\n type: 'grid',\n },\n args: {\n rows: {\n type: 'integer',\n description: 'The number of rows in the grid.',\n },\n cols: {\n type: 'integer',\n description: 'The number of columns in the grid.',\n },\n value: {\n type: 'any',\n description: 'The value to fill the grid with.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'rows',\n 'cols',\n 'value',\n ],\n },\n ],\n examples: [\n 'let { fill } = import(\"grid\");\\nfill(2, 3, 0)',\n 'let { fill } = import(\"grid\");\\nfill(2, 3, \"x\")',\n ],\n seeAlso: ['grid.generate', 'grid.from-array', 'vector.fill'],\n },\n 'generate': {\n category: 'grid',\n description: 'Generates a grid of the specified size, where each element is generated by the provided function.',\n returns: {\n type: 'grid',\n },\n args: {\n rows: {\n type: 'number',\n description: 'The number of rows in the grid.',\n },\n cols: {\n type: 'number',\n description: 'The number of columns in the grid.',\n },\n fn: {\n type: 'function',\n description: 'The function to generate the grid. It takes two arguments: the row index and the column index.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'rows',\n 'cols',\n 'fn',\n ],\n },\n ],\n examples: [\n 'let { generate } = import(\"grid\");\\ngenerate(3, 3, (i, j) -> i + j)',\n ],\n seeAlso: ['grid.fill', 'grid.from-array', 'vector.generate'],\n },\n 'reshape': {\n category: 'grid',\n 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.',\n returns: {\n type: 'grid',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'number',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { reshape } = import(\"grid\");\\nreshape([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n], 2)',\n ],\n seeAlso: ['grid.shape', 'grid.from-array'],\n },\n 'transpose': {\n category: 'grid',\n description: 'Transposes the grid `g`, swapping its rows and columns.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to transpose.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { transpose } = import(\"grid\");\\ntranspose([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n 'let { transpose } = import(\"grid\");\\ntranspose([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n])',\n 'let { transpose } = import(\"grid\");\\ntranspose([\\n [1, 2],\\n [3, 4],\\n])',\n ],\n seeAlso: ['grid.flip-h', 'grid.flip-v', 'grid.rotate'],\n },\n 'flip-h': {\n category: 'grid',\n description: 'Flips the grid `g` horizontally.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to flip horizontally.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { flip-h } = import(\"grid\");\\nflip-h([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n 'let { flip-h } = import(\"grid\");\\nflip-h([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n])',\n 'let { flip-h } = import(\"grid\");\\nflip-h([\\n [1, 2],\\n [3, 4],\\n])',\n ],\n seeAlso: ['grid.flip-v', 'grid.transpose', 'grid.rotate', 'grid.reverse-cols'],\n },\n 'flip-v': {\n category: 'grid',\n description: 'Flips the grid `g` vertically.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to flip vertically.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { flip-v } = import(\"grid\");\\nflip-v([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n 'let { flip-v } = import(\"grid\");\\nflip-v([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n])',\n 'let { flip-v } = import(\"grid\");\\nflip-v([\\n [1, 2],\\n [3, 4],\\n])',\n ],\n seeAlso: ['grid.flip-h', 'grid.transpose', 'grid.rotate', 'grid.reverse-rows'],\n },\n 'rotate': {\n category: 'grid',\n 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.',\n returns: {\n type: 'grid',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'integer',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { rotate } = import(\"grid\");\\nrotate([\\n [1, 2],\\n [3, 4],\\n], 1)',\n 'let { rotate } = import(\"grid\");\\nrotate([\\n [1, 2],\\n [3, 4],\\n], 2)',\n 'let { rotate } = import(\"grid\");\\nrotate([\\n [1, 2],\\n [3, 4],\\n], 3)',\n 'let { rotate } = import(\"grid\");\\nrotate([\\n [1, 2],\\n [3, 4],\\n], 4)',\n 'let { rotate } = import(\"grid\");\\nrotate([\\n [1, 2],\\n [3, 4],\\n], -1)',\n 'let { rotate } = import(\"grid\");\\nrotate([\\n [1, 2],\\n [3, 4],\\n], -2)',\n 'let { rotate } = import(\"grid\");\\nrotate([\\n [1, 2],\\n [3, 4],\\n], -3)',\n ],\n seeAlso: ['grid.transpose', 'grid.flip-h', 'grid.flip-v'],\n },\n 'reverse-rows': {\n category: 'grid',\n description: 'Reverses the order of rows in the grid `g`.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to reverse rows.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { reverse-rows } = import(\"grid\");\\nreverse-rows([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n 'let { reverse-rows } = import(\"grid\");\\nreverse-rows([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n])',\n 'let { reverse-rows } = import(\"grid\");\\nreverse-rows([\\n [1, 2],\\n [3, 4],\\n])',\n ],\n seeAlso: ['grid.reverse-cols', 'grid.flip-v'],\n },\n 'reverse-cols': {\n category: 'grid',\n description: 'Reverses the order of columns in the grid `g`.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to reverse columns.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { reverse-cols } = import(\"grid\");\\nreverse-cols([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n 'let { reverse-cols } = import(\"grid\");\\nreverse-cols([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n])',\n 'let { reverse-cols } = import(\"grid\");\\nreverse-cols([\\n [1, 2],\\n [3, 4],\\n])',\n ],\n seeAlso: ['grid.reverse-rows', 'grid.flip-h'],\n },\n 'slice': {\n category: 'grid',\n 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.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to slice.',\n },\n begin: {\n type: 'vector',\n description: 'The starting index of the slice as a vector of two numbers: `[row, col]`.',\n },\n stop: {\n type: 'vector',\n description: 'Optional ending index of the slice as a vector of two numbers: `[row, col]`.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'begin',\n ],\n },\n {\n argumentNames: [\n 'g',\n 'begin',\n 'stop',\n ],\n },\n ],\n examples: [\n '// 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])',\n '// 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])',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.slice-rows', 'grid.slice-cols'],\n },\n 'slice-rows': {\n category: 'grid',\n 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.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to slice.',\n },\n begin: {\n type: 'number',\n description: 'The starting index of the slice.',\n },\n stop: {\n type: 'number',\n description: 'Optional ending index of the slice.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'begin',\n ],\n },\n {\n argumentNames: [\n 'g',\n 'begin',\n 'stop',\n ],\n },\n ],\n examples: [\n 'let { slice-rows } = import(\"grid\");\\nslice-rows([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1, 2)',\n 'let { slice-rows } = import(\"grid\");\\nslice-rows([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1)',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.slice', 'grid.slice-cols', 'grid.splice-rows'],\n },\n 'slice-cols': {\n category: 'grid',\n 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.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to slice.',\n },\n begin: {\n type: 'number',\n description: 'The starting index of the slice.',\n },\n stop: {\n type: 'number',\n description: 'Optional ending index of the slice.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'begin',\n ],\n },\n {\n argumentNames: [\n 'g',\n 'begin',\n 'stop',\n ],\n },\n ],\n examples: [\n 'let { slice-cols } = import(\"grid\");\\nslice-cols([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1, 2)',\n 'let { slice-cols } = import(\"grid\");\\nslice-cols([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1)',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.slice', 'grid.slice-rows', 'grid.splice-cols'],\n },\n 'splice-rows': {\n category: 'grid',\n description: 'Splices rows of the grid `g` starting from the index `begin`. Deletes `deleteCount` rows and inserts the specified `items` at that position.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to splice.',\n },\n begin: {\n type: 'number',\n description: 'The starting index of the splice.',\n },\n deleteCount: {\n type: 'number',\n description: 'The number of rows to delete.',\n },\n items: {\n type: 'array',\n rest: true,\n description: 'The rows to insert.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'begin',\n 'deleteCount',\n ],\n },\n {\n argumentNames: [\n 'g',\n 'begin',\n 'deleteCount',\n 'items',\n ],\n },\n ],\n examples: [\n 'let { splice-rows } = import(\"grid\");\\nsplice-rows([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1, 2)',\n '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])',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.splice-cols', 'grid.slice-rows'],\n },\n 'splice-cols': {\n category: 'grid',\n description: 'Splices columns of the grid `g` starting from the index `begin`. Deletes `deleteCount` columns and inserts the specified `items` at that position.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to splice.',\n },\n begin: {\n type: 'number',\n description: 'The starting index of the splice.',\n },\n deleteCount: {\n type: 'number',\n description: 'The number of columns to delete.',\n },\n items: {\n type: 'array',\n rest: true,\n description: 'The columns to insert.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'begin',\n 'deleteCount',\n ],\n },\n {\n argumentNames: [\n 'g',\n 'begin',\n 'deleteCount',\n 'items',\n ],\n },\n ],\n examples: [\n 'let { splice-cols } = import(\"grid\");\\nsplice-cols([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], 1, 2)',\n '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\"])',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.splice-rows', 'grid.slice-cols'],\n },\n 'concat-rows': {\n category: 'grid',\n description: 'Concatenates two grids `a` and `b` by rows. The number of columns in both grids must be the same.',\n returns: {\n type: 'grid',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'grid',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { concat-rows } = import(\"grid\");\\nconcat-rows([\\n [\"Albert\", \"father\"],\\n [\"Nina\", \"mother\"],\\n [\"Kian\", \"son\"],\\n], [\\n [1, 2],\\n [3, 4],\\n])',\n ],\n seeAlso: ['grid.concat-cols', 'grid.push-rows'],\n },\n 'concat-cols': {\n category: 'grid',\n description: 'Concatenates two grids `a` and `b` by columns. The number of rows in both grids must be the same.',\n returns: {\n type: 'grid',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'grid',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n '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])',\n ],\n seeAlso: ['grid.concat-rows', 'grid.push-cols'],\n },\n 'map': {\n category: 'grid',\n description: 'Maps a function `a` over each element of the grid `b`, returning a new grid with the results.',\n returns: {\n type: 'grid',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n '// 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)',\n ],\n seeAlso: ['map', 'grid.mapi', 'grid.reduce'],\n },\n 'mapi': {\n category: 'grid',\n description: 'Maps a function `a` over each element of the grid `b`, passing the row and column index as additional arguments to the function.',\n returns: {\n type: 'grid',\n },\n args: {\n a: {\n type: 'grid',\n },\n b: {\n type: 'function',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n '// 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 ++ \")\")',\n ],\n seeAlso: ['grid.map', 'grid.reducei', 'map'],\n },\n 'reduce': {\n category: 'grid',\n description: 'Reduces the grid `a` using the function `b`, returning a single value.',\n returns: {\n type: 'any',\n },\n args: {\n 'g': {\n type: 'grid',\n description: 'The grid to reduce.',\n },\n 'fn': {\n type: 'function',\n description: 'The function to reduce the grid. It takes two arguments: the accumulator and the current element.',\n },\n 'initial-value': {\n type: 'any',\n description: 'The initial value for the accumulator.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'fn',\n 'initial-value',\n ],\n },\n ],\n examples: [\n '// 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], ++, \"\")',\n ],\n seeAlso: ['reduce', 'grid.reducei', 'grid.map'],\n },\n 'reducei': {\n category: 'grid',\n description: 'Reduces the grid `a` using the function `b`, passing the row and column indices as additional arguments to the function.',\n returns: {\n type: 'any',\n },\n args: {\n 'g': {\n type: 'grid',\n description: 'The grid to reduce.',\n },\n 'fn': {\n type: 'function',\n description: 'The function to reduce the grid. It takes four arguments: the accumulator, the current element, the row index, and the column index.',\n },\n 'initial-value': {\n type: 'any',\n description: 'The initial value for the accumulator.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'fn',\n 'initial-value',\n ],\n },\n ],\n examples: [\n '// 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], ++, \"\")',\n ],\n seeAlso: ['grid.reduce', 'grid.mapi', 'reduce'],\n },\n 'push-rows': {\n category: 'grid',\n description: 'Pushes the specified rows into the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to push rows into.',\n },\n rows: {\n type: 'array',\n rest: true,\n description: 'The rows to push into the grid.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'rows',\n ],\n },\n ],\n examples: [\n 'let { push-rows } = import(\"grid\");\\npush-rows([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], [\"Nazanin\", \"mother\", 40])',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.unshift-rows', 'grid.pop-row', 'grid.shift-row', 'grid.concat-rows'],\n },\n 'unshift-rows': {\n category: 'grid',\n description: 'Unshifts the specified rows into the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to unshift rows into.',\n },\n rows: {\n type: 'array',\n rest: true,\n description: 'The rows to unshift into the grid.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'rows',\n ],\n },\n ],\n examples: [\n 'let { unshift-rows } = import(\"grid\");\\nunshift-rows([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], [\"Nazanin\", \"mother\", 40])',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.push-rows', 'grid.shift-row', 'grid.pop-row'],\n },\n 'pop-row': {\n category: 'grid',\n description: 'Pops the last row from the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to pop a row from.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { pop-row } = import(\"grid\");\\npop-row([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n ],\n seeAlso: ['grid.shift-row', 'grid.push-rows', 'grid.unshift-rows'],\n },\n 'shift-row': {\n category: 'grid',\n description: 'Shifts the first row from the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to shift a row from.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { shift-row } = import(\"grid\");\\nshift-row([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n ],\n seeAlso: ['grid.pop-row', 'grid.push-rows', 'grid.unshift-rows'],\n },\n 'push-cols': {\n category: 'grid',\n description: 'Pushes the specified columns into the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to push columns into.',\n },\n cols: {\n type: 'array',\n rest: true,\n description: 'The columns to push into the grid.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'cols',\n ],\n },\n ],\n examples: [\n 'let { push-cols } = import(\"grid\");\\npush-cols([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], [\"f\", \"m\", \"s\"])',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.unshift-cols', 'grid.pop-col', 'grid.shift-col', 'grid.concat-cols'],\n },\n 'unshift-cols': {\n category: 'grid',\n description: 'Unshifts the specified columns into the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to unshift columns into.',\n },\n cols: {\n type: 'array',\n rest: true,\n description: 'The columns to unshift into the grid.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n 'cols',\n ],\n },\n ],\n examples: [\n 'let { unshift-cols } = import(\"grid\");\\nunshift-cols([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n], [\"f\", \"m\", \"s\"])',\n ],\n hideOperatorForm: true,\n seeAlso: ['grid.push-cols', 'grid.shift-col', 'grid.pop-col'],\n },\n 'pop-col': {\n category: 'grid',\n description: 'Pops the last column from the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to pop a column from.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { pop-col } = import(\"grid\");\\npop-col([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n ],\n seeAlso: ['grid.shift-col', 'grid.push-cols', 'grid.unshift-cols'],\n },\n 'shift-col': {\n category: 'grid',\n description: 'Shifts the first column from the grid `g` and returns the new grid.',\n returns: {\n type: 'grid',\n },\n args: {\n g: {\n type: 'grid',\n description: 'The grid to shift a column from.',\n },\n },\n variants: [\n {\n argumentNames: [\n 'g',\n ],\n },\n ],\n examples: [\n 'let { shift-col } = import(\"grid\");\\nshift-col([\\n [\"Albert\", \"father\", 10],\\n [\"Nina\", \"mother\", 20],\\n [\"Kian\", \"son\", 30],\\n])',\n ],\n seeAlso: ['grid.pop-col', 'grid.push-cols', 'grid.unshift-cols'],\n },\n 'from-array': {\n category: 'grid',\n 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.',\n returns: {\n type: 'grid',\n },\n args: {\n a: {\n type: 'array',\n },\n b: {\n type: 'number',\n },\n },\n variants: [\n {\n argumentNames: [\n 'a',\n 'b',\n ],\n },\n ],\n examples: [\n 'let { from-array } = import(\"grid\");\\nfrom-array([1, 2, 3, 4], 2)',\n 'let { from-array } = import(\"grid\");\\nfrom-array([1, 2, 3, 4], 4)',\n ],\n seeAlso: ['grid.fill', 'grid.generate', 'grid.reshape'],\n },\n}\n","import type { Any } from '../../../interface'\n\nexport function transpose<T extends Any>(grid: T[][]): T[][] {\n const result: T[][] = []\n\n for (let i = 0; i < grid[0]!.length; i += 1) {\n const row: T[] = []\n for (let j = 0; j < grid.length; j += 1) {\n row.push(grid[j]![i]!)\n }\n result.push(row)\n }\n return result\n}\n","import { LitsError } from '../../../errors'\nimport type { Any } from '../../../interface'\nimport { assertGrid, assertVector } from '../../../typeGuards/annotatedArrays'\nimport { assertArray } from '../../../typeGuards/array'\nimport { asAny, asFunctionLike, assertAny, assertFunctionLike } from '../../../typeGuards/lits'\nimport { assertNumber } from '../../../typeGuards/number'\nimport { toFixedArity } from '../../../utils/arity'\nimport type { MaybePromise } from '../../../utils/maybePromise'\nimport { chain, everySequential, mapSequential, reduceSequential, someSequential } from '../../../utils/maybePromise'\nimport type { BuiltinNormalExpressions } from '../../../builtin/interface'\nimport type { LitsModule } from '../interface'\nimport { moduleDocs } from './docs'\nimport { fromArray } from './fromArray'\nimport { transpose } from './transpose'\n\nconst gridFunctions: BuiltinNormalExpressions = {\n 'every?': {\n evaluate: ([grid, predicate], sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<boolean> => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(predicate, sourceCodeInfo)\n\n const cells: Any[] = []\n for (const row of grid) {\n for (const cell of row) {\n cells.push(cell)\n }\n }\n return everySequential(cells, cell => executeFunction(predicate, [cell], contextStack, sourceCodeInfo))\n },\n arity: toFixedArity(2),\n },\n 'some?': {\n evaluate: ([grid, predicate], sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<boolean> => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(predicate, sourceCodeInfo)\n\n const cells: Any[] = []\n for (const row of grid) {\n for (const cell of row) {\n cells.push(cell)\n }\n }\n return someSequential(cells, cell => executeFunction(predicate, [cell], contextStack, sourceCodeInfo))\n },\n arity: toFixedArity(2),\n },\n 'every-row?': {\n evaluate: ([grid, predicate], sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<boolean> => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(predicate, sourceCodeInfo)\n\n return everySequential(Array.from(grid), row => executeFunction(predicate, [row], contextStack, sourceCodeInfo))\n },\n arity: toFixedArity(2),\n },\n 'some-row?': {\n evaluate: ([grid, predicate], sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<boolean> => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(predicate, sourceCodeInfo)\n\n return someSequential(Array.from(grid), row => executeFunction(predicate, [row], contextStack, sourceCodeInfo))\n },\n arity: toFixedArity(2),\n },\n 'every-col?': {\n evaluate: ([grid, predicate], sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<boolean> => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(predicate, sourceCodeInfo)\n\n const transposed = transpose(grid)\n return everySequential(Array.from(transposed), row => executeFunction(predicate, [row], contextStack, sourceCodeInfo))\n },\n arity: toFixedArity(2),\n },\n 'some-col?': {\n evaluate: ([grid, predicate], sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<boolean> => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(predicate, sourceCodeInfo)\n\n const transposed = transpose(grid)\n return someSequential(Array.from(transposed), row => executeFunction(predicate, [row], contextStack, sourceCodeInfo))\n },\n arity: toFixedArity(2),\n },\n 'row': {\n evaluate: ([grid, row], sourceCodeInfo): Any[] => {\n assertGrid(grid, sourceCodeInfo)\n assertNumber(row, sourceCodeInfo, { integer: true, nonNegative: true, lt: grid.length })\n return grid[row]!\n },\n arity: toFixedArity(2),\n },\n 'col': {\n evaluate: ([grid, col], sourceCodeInfo): Any[] => {\n assertGrid(grid, sourceCodeInfo)\n assertNumber(col, sourceCodeInfo, { integer: true, nonNegative: true, lt: grid[0]!.length })\n return grid.map(row => row[col]!)\n },\n arity: toFixedArity(2),\n },\n 'shape': {\n evaluate: ([grid], sourceCodeInfo): Any[] => {\n assertGrid(grid, sourceCodeInfo)\n return [grid.length, grid[0]!.length]\n },\n arity: toFixedArity(1),\n },\n 'fill': {\n evaluate: ([rows, cols, value], sourceCodeInfo): Any[][] => {\n assertNumber(rows, sourceCodeInfo, { integer: true, positive: true })\n assertNumber(cols, sourceCodeInfo, { integer: true, positive: true })\n assertAny(value, sourceCodeInfo)\n const result: Any[][] = []\n for (let i = 0; i < rows; i += 1) {\n const row: Any[] = []\n for (let j = 0; j < cols; j += 1) {\n row.push(value)\n }\n result.push(row)\n }\n return result\n },\n arity: toFixedArity(3),\n },\n 'generate': {\n evaluate: ([rows, cols, generator], sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<Any[][]> => {\n assertNumber(rows, sourceCodeInfo, { integer: true, positive: true })\n assertNumber(cols, sourceCodeInfo, { integer: true, positive: true })\n assertFunctionLike(generator, sourceCodeInfo)\n\n return mapSequential(Array.from({ length: rows }), (_, i) => {\n return mapSequential(Array.from({ length: cols }), (__, j) => {\n return chain(\n executeFunction(generator, [i, j], contextStack, sourceCodeInfo),\n (value) => {\n assertAny(value, sourceCodeInfo)\n return value\n },\n )\n })\n })\n },\n arity: toFixedArity(3),\n },\n 'reshape': {\n evaluate: ([grid, rows], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertNumber(rows, sourceCodeInfo, { integer: true, positive: true })\n\n const flatTable = grid.flat()\n if (flatTable.length % rows !== 0) {\n throw new LitsError(`The number of elements in the grid must be divisible by rows, but got ${flatTable.length} and ${rows}`, sourceCodeInfo)\n }\n const cols = flatTable.length / rows\n\n const result: Any[][] = []\n for (let i = 0; i < rows; i += 1) {\n const row: Any[] = []\n for (let j = 0; j < cols; j += 1) {\n row.push(flatTable[i * cols + j]!)\n }\n result.push(row)\n }\n return result\n },\n arity: toFixedArity(2),\n },\n 'transpose': {\n evaluate: ([grid], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n return transpose(grid)\n },\n arity: toFixedArity(1),\n },\n 'flip-h': {\n evaluate: ([grid], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n return grid.map(row => row.reverse())\n },\n arity: toFixedArity(1),\n },\n 'flip-v': {\n evaluate: ([grid], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n return grid.reverse()\n },\n arity: toFixedArity(1),\n },\n 'rotate': {\n evaluate: ([grid, times], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertNumber(times, sourceCodeInfo, { integer: true })\n // Normalize times to be between 0 and 3\n times = ((times % 4) + 4) % 4\n\n // If times is 0, return the original grid\n if (times === 0 || grid.length === 0) {\n return grid.map(row => [...row])\n }\n\n const height = grid.length\n const width = grid[0]!.length\n\n let result: Any[][]\n\n switch (times) {\n case 1: // 90 degrees clockwise\n result = Array<Any>(width).fill(null).map(() => Array<Any>(height).fill(null))\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n result[x]![height - 1 - y] = grid[y]![x]!\n }\n }\n break\n\n case 2: // 180 degrees\n result = Array<Any>(height).fill(null).map(() => Array<Any>(width).fill(null))\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n result[height - 1 - y]![width - 1 - x] = grid[y]![x]!\n }\n }\n break\n\n case 3: // 270 degrees clockwise (or 90 degrees counter-clockwise)\n result = Array<Any>(width).fill(null).map(() => Array<Any>(height).fill(null))\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n result[width - 1 - x]![y] = grid[y]![x]!\n }\n }\n break\n }\n\n return result!\n },\n arity: toFixedArity(2),\n },\n 'reverse-rows': {\n evaluate: ([grid], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n return grid.reverse()\n },\n arity: toFixedArity(1),\n },\n 'reverse-cols': {\n evaluate: ([grid], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n return grid.map(row => row.reverse())\n },\n arity: toFixedArity(1),\n },\n 'slice': {\n evaluate: ([grid, start, end], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertVector(start, sourceCodeInfo)\n if (start.length !== 2) {\n throw new LitsError(`The start vector must have 2 elements, but got ${start.length}`, sourceCodeInfo)\n }\n const [rowStart, colStart] = start\n assertNumber(rowStart, sourceCodeInfo, { integer: true, nonNegative: true, lt: grid.length })\n assertNumber(colStart, sourceCodeInfo, { integer: true, nonNegative: true, lt: grid[0]!.length })\n\n end ??= [grid.length, grid[0]!.length]\n assertVector(end, sourceCodeInfo)\n if (end.length !== 2) {\n throw new LitsError(`The end vector must have 2 elements, but got ${end.length}`, sourceCodeInfo)\n }\n const [rowEnd, colEnd] = end\n assertNumber(rowEnd, sourceCodeInfo, { gt: rowStart, lte: grid.length })\n assertNumber(colEnd, sourceCodeInfo, { gt: colStart, lte: grid[0]!.length })\n\n const result: Any[][] = []\n for (let i = rowStart; i < rowEnd; i += 1) {\n const row: Any[] = []\n for (let j = colStart; j < colEnd; j += 1) {\n row.push(grid[i]![j]!)\n }\n result.push(row)\n }\n return result\n },\n arity: { min: 2, max: 3 },\n },\n 'slice-rows': {\n evaluate: ([grid, rowStart, rowEnd], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n\n if (typeof rowEnd === 'undefined') {\n assertNumber(rowStart, sourceCodeInfo, { integer: true, lte: grid.length, gte: -grid.length })\n if (rowStart < 0) {\n return grid.slice(grid.length + rowStart)\n }\n return grid.slice(rowStart)\n }\n\n assertNumber(rowStart, sourceCodeInfo, { integer: true, nonNegative: true, lte: grid.length })\n assertNumber(rowEnd, sourceCodeInfo, { integer: true })\n rowEnd = rowEnd < 0 ? grid.length + rowEnd : rowEnd\n assertNumber(rowEnd, sourceCodeInfo, { gt: rowStart, lte: grid.length })\n\n return grid.slice(rowStart, rowEnd)\n },\n arity: { min: 2, max: 3 },\n },\n 'slice-cols': {\n evaluate: ([grid, colStart, colEnd], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n const trMatrix = transpose(grid)\n\n if (typeof colEnd === 'undefined') {\n assertNumber(colStart, sourceCodeInfo, { integer: true, lte: trMatrix.length, gte: -trMatrix.length })\n if (colStart < 0) {\n return transpose(trMatrix.slice(trMatrix.length + colStart))\n }\n return transpose(trMatrix.slice(colStart))\n }\n\n assertNumber(colStart, sourceCodeInfo, { integer: true, nonNegative: true, lte: trMatrix.length })\n assertNumber(colEnd, sourceCodeInfo, { integer: true })\n colEnd = colEnd < 0 ? trMatrix.length + colEnd : colEnd\n assertNumber(colEnd, sourceCodeInfo, { gt: colStart, lte: trMatrix.length })\n\n return transpose(trMatrix.slice(colStart, colEnd))\n },\n arity: { min: 2, max: 3 },\n },\n 'splice-rows': {\n evaluate: ([grid, rowStart, rowDeleteCount, ...rows], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertNumber(rowStart, sourceCodeInfo, { integer: true, nonNegative: true, lte: grid.length })\n assertNumber(rowDeleteCount, sourceCodeInfo, { integer: true, nonNegative: true })\n if (rows.length !== 0) {\n assertGrid(rows, sourceCodeInfo)\n rows.every((row) => {\n assertArray(row, sourceCodeInfo)\n if (grid[0]!.length !== row.length) {\n throw new LitsError(`All rows must have the same length as the number of columns in grid, but got ${row.length}`, sourceCodeInfo)\n }\n return true\n })\n }\n\n const result: Any[][] = []\n for (let i = 0; i < rowStart; i += 1) {\n result.push(grid[i]!)\n }\n if (rows.length > 0) {\n result.push(...(rows as Any[][]))\n }\n for (let i = rowStart + rowDeleteCount; i < grid.length; i += 1) {\n result.push(grid[i]!)\n }\n return result\n },\n arity: { min: 3 },\n },\n 'splice-cols': {\n evaluate: ([grid, colStart, colDeleteCount, ...cols], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n const trMatrix = transpose(grid)\n assertNumber(colStart, sourceCodeInfo, { integer: true, nonNegative: true, lte: trMatrix.length })\n assertNumber(colDeleteCount, sourceCodeInfo, { integer: true, nonNegative: true })\n\n if (cols.length !== 0) {\n assertGrid(cols, sourceCodeInfo)\n cols.every((row) => {\n assertArray(row, sourceCodeInfo)\n if (trMatrix[0]!.length !== row.length) {\n throw new LitsError(`All rows must have the same length as the number of rows in grid, but got ${row.length}`, sourceCodeInfo)\n }\n return true\n })\n }\n\n const result: Any[][] = []\n for (let i = 0; i < colStart; i += 1) {\n result.push(trMatrix[i]!)\n }\n result.push(...(cols as Any[][]))\n for (let i = colStart + colDeleteCount; i < trMatrix.length; i += 1) {\n result.push(trMatrix[i]!)\n }\n return transpose(result)\n },\n arity: { min: 3 },\n },\n 'concat-rows': {\n evaluate: (params, sourceCodeInfo): Any[][] => {\n assertArray(params, sourceCodeInfo)\n params.every(grid => assertGrid(grid, sourceCodeInfo))\n const cols = (params[0] as Any[][])[0]!.length\n ;(params as Any[][][]).slice(1).every((grid) => {\n if (grid[0]!.length !== cols) {\n throw new LitsError(`All grids must have the same number of columns, but got ${cols} and ${grid[0]!.length}`, sourceCodeInfo)\n }\n return true\n })\n\n const result: Any[][] = []\n ;(params as Any[][][]).forEach((grid) => {\n grid.forEach((row) => {\n result.push(row)\n })\n })\n return result\n },\n arity: { min: 1 },\n },\n 'concat-cols': {\n evaluate: (params, sourceCodeInfo): Any[][] => {\n assertArray(params, sourceCodeInfo)\n params.every(grid => assertGrid(grid, sourceCodeInfo))\n const rows = (params[0] as Any[][]).length\n ;(params as Any[][][]).slice(1).every((grid) => {\n if (grid.length !== rows) {\n throw new LitsError(`All grids must have the same number of rows, but got ${rows} and ${grid.length}`, sourceCodeInfo)\n }\n return true\n })\n\n const result: Any[][] = []\n for (let i = 0; i < rows; i += 1) {\n const row: Any[] = []\n ;(params as Any[][][]).forEach((grid) => {\n row.push(...grid[i]!)\n })\n result.push(row)\n }\n return result\n },\n arity: { min: 1 },\n },\n 'map': {\n evaluate: (params, sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<Any[][]> => {\n const fn = asFunctionLike(params.at(-1), sourceCodeInfo)\n const grids = params.slice(0, -1)\n assertGrid(grids[0], sourceCodeInfo)\n const rows = grids[0].length\n const cols = grids[0][0]!.length\n grids.slice(1).forEach((grid) => {\n assertGrid(grid, sourceCodeInfo)\n if (grid.length !== rows) {\n throw new LitsError(`All grids must have the same number of rows, but got ${rows} and ${grid.length}`, sourceCodeInfo)\n }\n if (grid[0]!.length !== cols) {\n throw new LitsError(`All grids must have the same number of columns, but got ${cols} and ${grid[0]!.length}`, sourceCodeInfo)\n }\n })\n\n return mapSequential(Array.from({ length: rows }), (_, i) => {\n return mapSequential(Array.from({ length: cols }), (__, j) => {\n const args = grids.map(grid => (grid as Any[][])[i]![j])\n return chain(executeFunction(fn, args, contextStack, sourceCodeInfo), val => asAny(val))\n })\n })\n },\n arity: { min: 2 },\n },\n 'mapi': {\n evaluate: ([grid, fn], sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<Any[][]> => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(fn, sourceCodeInfo)\n\n const rows = grid.length\n const cols = grid[0]!.length\n\n return mapSequential(Array.from({ length: rows }), (_, i) => {\n return mapSequential(Array.from({ length: cols }), (__, j) => {\n return chain(executeFunction(fn, [grid[i]![j], i, j], contextStack, sourceCodeInfo), val => asAny(val))\n })\n })\n },\n arity: toFixedArity(2),\n },\n 'reduce': {\n evaluate: ([grid, fn, initialValue], sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<Any> => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(fn, sourceCodeInfo)\n\n const cells: Any[] = []\n for (const row of grid) {\n for (const cell of row) {\n cells.push(cell)\n }\n }\n return reduceSequential(\n cells,\n (accumulator, cell) => executeFunction(fn, [accumulator, cell], contextStack, sourceCodeInfo),\n asAny(initialValue),\n )\n },\n arity: toFixedArity(3),\n },\n 'reducei': {\n evaluate: ([grid, fn, initialValue], sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<Any> => {\n assertGrid(grid, sourceCodeInfo)\n assertFunctionLike(fn, sourceCodeInfo)\n\n const cells: { cell: Any, i: number, j: number }[] = []\n for (let i = 0; i < grid.length; i += 1) {\n for (let j = 0; j < grid[i]!.length; j += 1) {\n cells.push({ cell: grid[i]![j]!, i, j })\n }\n }\n return reduceSequential(\n cells,\n (accumulator, { cell, i, j }) => executeFunction(fn, [accumulator, cell, i, j], contextStack, sourceCodeInfo),\n asAny(initialValue),\n )\n },\n arity: toFixedArity(3),\n },\n 'push-rows': {\n evaluate: ([grid, ...rows], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertGrid(rows, sourceCodeInfo)\n if (grid[0]!.length !== rows[0]!.length) {\n throw new LitsError(`All rows must have the same length as the number of columns in grid, but got ${grid[0]!.length} and ${rows[0]!.length}`, sourceCodeInfo)\n }\n return [...grid, ...rows]\n },\n arity: { min: 2 },\n },\n 'unshift-rows': {\n evaluate: ([grid, ...rows], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertGrid(rows, sourceCodeInfo)\n if (grid[0]!.length !== rows[0]!.length) {\n throw new LitsError(`All rows must have the same length as the number of columns in grid, but got ${grid[0]!.length} and ${rows[0]!.length}`, sourceCodeInfo)\n }\n return [...rows, ...grid]\n },\n arity: { min: 2 },\n },\n 'pop-row': {\n evaluate: ([grid], sourceCodeInfo): Any[][] | null => {\n assertGrid(grid, sourceCodeInfo)\n if (grid.length === 1) {\n return null\n }\n return grid.slice(0, -1)\n },\n arity: toFixedArity(1),\n\n },\n 'shift-row': {\n evaluate: ([grid], sourceCodeInfo): Any[][] | null => {\n assertGrid(grid, sourceCodeInfo)\n if (grid.length === 1) {\n return null\n }\n return grid.slice(1)\n },\n arity: toFixedArity(1),\n },\n 'push-cols': {\n evaluate: ([grid, ...cols], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertGrid(cols, sourceCodeInfo)\n if (grid.length !== cols[0]!.length) {\n throw new LitsError(`All columns must have the same length as the number of rows in grid, but got ${cols.length}`, sourceCodeInfo)\n }\n\n const result: Any[][] = []\n\n for (let i = 0; i < grid.length; i += 1) {\n const row: Any[] = []\n row.push(...grid[i]!)\n cols.forEach((col) => {\n row.push(col[i]!)\n })\n result.push(row)\n }\n return result\n },\n arity: { min: 2 },\n },\n 'unshift-cols': {\n evaluate: ([grid, ...cols], sourceCodeInfo): Any[][] => {\n assertGrid(grid, sourceCodeInfo)\n assertGrid(cols, sourceCodeInfo)\n if (grid.length !== cols[0]!.length) {\n throw new LitsError(`All columns must have the same length as the number of rows in grid, but got ${cols.length}`, sourceCodeInfo)\n }\n\n const result: Any[][] = []\n\n for (let i = 0; i < grid.length; i += 1) {\n const row: Any[] = []\n cols.forEach((col) => {\n row.push(col[i]!)\n })\n row.push(...grid[i]!)\n result.push(row)\n }\n return result\n },\n arity: { min: 2 },\n },\n 'pop-col': {\n evaluate: ([grid], sourceCodeInfo): Any[][] | null => {\n assertGrid(grid, sourceCodeInfo)\n if (grid[0]!.length === 1) {\n return null\n }\n return grid.map(row => row.slice(0, -1))\n },\n arity: toFixedArity(1),\n },\n 'shift-col': {\n evaluate: ([grid], sourceCodeInfo): Any[][] | null => {\n assertGrid(grid, sourceCodeInfo)\n if (grid[0]!.length === 1) {\n return null\n }\n return grid.map(row => row.slice(1))\n },\n arity: toFixedArity(1),\n },\n 'from-array': {\n evaluate: ([array, rows], sourceCodeInfo): unknown[][] => {\n assertArray(array, sourceCodeInfo)\n assertNumber(rows, sourceCodeInfo, { integer: true, positive: true })\n if (array.length % rows !== 0) {\n throw new LitsError(`The number of elements in the array must be divisible by rows, but got ${array.length} and ${rows}`, sourceCodeInfo)\n }\n return fromArray(array, rows)\n },\n arity: toFixedArity(2),\n },\n}\n\n/**\n * The grid module containing 2D array manipulation functions.\n */\nfor (const [key, docs] of Object.entries(moduleDocs)) {\n if (gridFunctions[key])\n gridFunctions[key].docs = docs\n}\n\nexport const gridModule: LitsModule = {\n name: 'grid',\n functions: gridFunctions,\n}\n","/**\n * Creates a grid from a flat array with specified dimensions\n *\n * @param flatArray The flat array of values\n * @param rows Number of rows in the resulting grid\n * @returns A 2D array representing the grid\n */\nexport function fromArray(flatArray: unknown[], rows: number): unknown[][] {\n // Create the grid\n const grid: unknown[][] = []\n const cols = flatArray.length / rows\n // Reshape the flat array into rows and columns\n for (let i = 0; i < rows; i++) {\n const start = i * cols\n const end = start + cols\n grid.push(flatArray.slice(start, end))\n }\n\n return grid\n}\n"],"names":["getCodeMarker","sourceCodeInfo","position","code","leftPadding","column","rightPadding","length","repeat","Math","max","LitsError","Error","shortMessage","constructor","err","message","super","location","line","filePath","getLitsErrorMessage","this","Object","setPrototypeOf","prototype","name","NodeTypes","Number","String","NormalExpression","SpecialExpression","UserDefinedSymbol","NormalBuiltinSymbol","SpecialBuiltinSymbol","ReservedSymbol","Binding","Spread","NodeTypesSet","Set","values","functionTypeSet","FUNCTION_SYMBOL","REGEXP_SYMBOL","isLitsFunction","func","type","functionType","has","isNode","value","Array","isArray","valueToString","keys","find","key","RegExp","toString","JSON","stringify","getSourceCodeInfo","anyValue","isNumber","options","isNaN","integer","isInteger","finite","isFinite","zero","nonZero","positive","negative","nonPositive","nonNegative","gt","gte","lt","lte","assertNumber","sign","getSignString","numberType","range","getRangeString","filter","x","join","getNumberTypeName","annotatedArrays","WeakSet","vectors","notVectors","grids","notGrids","assertVector","vector","every","elem","add","isVector","assertGrid","grid","nbrOfCols","row","slice","isGrid","getAssertionError","typeName","assertArray","asAny","assertAny","undefined","isAny","isObj","regexp","isColl","isSeq","assertFunctionLike","isFunctionLike","toFixedArity","arity","min","chain","fn","Promise","then","mapSequential","arr","results","i","result","chainRemainingMap","push","async","currentPromise","startIndex","reduceSequential","initial","next","chainRemainingReduce","someSequential","chainRemainingSome","everySequential","chainRemainingEvery","moduleDocs","category","description","returns","args","a","b","variants","argumentNames","examples","seeAlso","col","shape","g","fill","rows","cols","generate","reshape","transpose","rotate","begin","stop","hideOperatorForm","deleteCount","items","rest","map","mapi","reduce","reducei","j","gridFunctions","evaluate","predicate","contextStack","executeFunction","cells","cell","from","transposed","generator","_","__","flatTable","flat","reverse","times","height","width","y","start","end","rowStart","colStart","rowEnd","colEnd","trMatrix","rowDeleteCount","colDeleteCount","params","forEach","asFunctionLike","at","val","initialValue","accumulator","array","flatArray","fromArray","docs","entries","gridModule","functions"],"mappings":"AAEM,SAAUA,EAAcC,GAC5B,IAAKA,EAAeC,WAAaD,EAAeE,KAC9C,MAAO,GAET,MAAMC,EAAcH,EAAeC,SAASG,OAAS,EAC/CC,EAAeL,EAAeE,KAAKI,OAASH,EAAc,EAChE,MAAO,GAAG,IAAII,OAAOC,KAAKC,IAAIN,EAAa,OAAO,IAAII,OAAOC,KAAKC,IAAIJ,EAAc,KACtF,CCkBM,MAAOK,UAAkBC,MACbX,eACAY,aAChB,WAAAC,CAAYC,EAAcd,GACxB,MAAMe,EAAUD,aAAeH,MAC3BG,EAAIC,QACJ,GAAGD,IAEPE,MA/BJ,SAA6BD,EAAiBf,GAC5C,IAAKA,EACH,OAAOe,EAET,MAAME,EAAW,GAAGjB,EAAeC,SAASiB,QAAQlB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