@mojir/lits 2.2.3 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -8
- package/dist/cli/cli.js +1264 -909
- package/dist/cli/src/Lits/Lits.d.ts +8 -2
- package/dist/cli/src/builtin/bindingNode.d.ts +2 -1
- package/dist/cli/src/builtin/interface.d.ts +3 -2
- package/dist/cli/src/builtin/modules/number-theory/sequences/index.d.ts +2 -1
- package/dist/cli/src/evaluator/functionExecutors.d.ts +2 -1
- package/dist/cli/src/evaluator/index.d.ts +3 -2
- package/dist/cli/src/evaluator/interface.d.ts +3 -2
- package/dist/cli/src/utils/maybePromise.d.ts +54 -0
- package/dist/full.esm.js +1 -1
- package/dist/full.esm.js.map +1 -1
- package/dist/full.js +1 -1
- package/dist/full.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +1 -1
- package/dist/lits.iife.js.map +1 -1
- package/dist/modules/assert.esm.js +1 -1
- package/dist/modules/assert.esm.js.map +1 -1
- package/dist/modules/assert.js +1 -1
- package/dist/modules/assert.js.map +1 -1
- package/dist/modules/collection.esm.js +1 -1
- package/dist/modules/collection.esm.js.map +1 -1
- package/dist/modules/collection.js +1 -1
- package/dist/modules/collection.js.map +1 -1
- package/dist/modules/grid.esm.js +1 -1
- package/dist/modules/grid.esm.js.map +1 -1
- package/dist/modules/grid.js +1 -1
- package/dist/modules/grid.js.map +1 -1
- package/dist/modules/number-theory.esm.js +1 -1
- package/dist/modules/number-theory.esm.js.map +1 -1
- package/dist/modules/number-theory.js +1 -1
- package/dist/modules/number-theory.js.map +1 -1
- package/dist/modules/sequence.esm.js +1 -1
- package/dist/modules/sequence.esm.js.map +1 -1
- package/dist/modules/sequence.js +1 -1
- package/dist/modules/sequence.js.map +1 -1
- package/dist/modules/src/Lits/Lits.d.ts +8 -2
- package/dist/modules/src/builtin/bindingNode.d.ts +2 -1
- package/dist/modules/src/builtin/interface.d.ts +3 -2
- package/dist/modules/src/builtin/modules/number-theory/sequences/index.d.ts +2 -1
- package/dist/modules/src/evaluator/functionExecutors.d.ts +2 -1
- package/dist/modules/src/evaluator/index.d.ts +3 -2
- package/dist/modules/src/evaluator/interface.d.ts +3 -2
- package/dist/modules/src/utils/maybePromise.d.ts +54 -0
- package/dist/modules/vector.esm.js +1 -1
- package/dist/modules/vector.esm.js.map +1 -1
- package/dist/modules/vector.js +1 -1
- package/dist/modules/vector.js.map +1 -1
- package/dist/src/Lits/Lits.d.ts +8 -2
- package/dist/src/builtin/bindingNode.d.ts +2 -1
- package/dist/src/builtin/interface.d.ts +3 -2
- package/dist/src/builtin/modules/number-theory/sequences/index.d.ts +2 -1
- package/dist/src/evaluator/functionExecutors.d.ts +2 -1
- package/dist/src/evaluator/index.d.ts +3 -2
- package/dist/src/evaluator/interface.d.ts +3 -2
- package/dist/src/utils/maybePromise.d.ts +54 -0
- package/dist/testFramework.esm.js +1 -1
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +1 -1
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sequence.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/utils/getAssertionError.ts","../../src/typeGuards/array.ts","../../src/typeGuards/index.ts","../../src/typeGuards/litsFunction.ts","../../src/typeGuards/lits.ts","../../src/typeGuards/number.ts","../../src/typeGuards/string.ts","../../src/utils/index.ts","../../src/utils/arity.ts","../../src/builtin/modules/sequence/index.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 './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 { LitsError } from '../errors'\nimport type { UnknownRecord } from '../interface'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { valueToString } from '../utils/debug/debugTools'\nimport { getSourceCodeInfo } from '../utils/debug/getSourceCodeInfo'\n\nfunction isNonUndefined<T>(value: T | undefined): value is T {\n return value !== undefined\n}\n\nexport function asNonUndefined<T>(value: T | undefined, sourceCodeInfo?: SourceCodeInfo): T {\n assertNonUndefined(value, sourceCodeInfo)\n return value\n}\n\nexport function assertNonUndefined<T>(value: T | undefined, sourceCodeInfo?: SourceCodeInfo): asserts value is T {\n if (!isNonUndefined(value))\n throw new LitsError('Unexpected undefined', getSourceCodeInfo(value, sourceCodeInfo))\n}\n\nexport function isUnknownRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\nexport function assertUnknownRecord(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is UnknownRecord {\n if (!isUnknownRecord(value)) {\n throw new LitsError(\n `Expected ${'UnknownRecord'}, got ${valueToString(value)}.`,\n getSourceCodeInfo(value, sourceCodeInfo),\n )\n }\n}\n\nexport function asUnknownRecord(value: unknown, sourceCodeInfo?: SourceCodeInfo): UnknownRecord {\n assertUnknownRecord(value, sourceCodeInfo)\n return value\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 { 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 type { SourceCodeInfo } from '../tokenizer/token'\nimport { getAssertionError } from '../utils/getAssertionError'\n\ntype StringAssertionOptions =\n | {\n nonEmpty?: true\n char?: never\n }\n | {\n nonEmpty?: never\n char?: true\n }\n\nexport function isString(value: unknown, options: StringAssertionOptions = {}): value is string {\n if (typeof value !== 'string')\n return false\n\n if (options.nonEmpty && value.length === 0)\n return false\n\n if (options.char && value.length !== 1)\n return false\n\n return true\n}\n\nexport function assertString(\n value: unknown,\n sourceCodeInfo: SourceCodeInfo | undefined,\n options: StringAssertionOptions = {},\n): asserts value is string {\n if (!isString(value, options)) {\n throw getAssertionError(\n `${options.nonEmpty ? 'non empty string' : options.char ? 'character' : 'string'}`,\n value,\n sourceCodeInfo,\n )\n }\n}\n\nexport function asString(\n value: unknown,\n sourceCodeInfo: SourceCodeInfo | undefined,\n options: StringAssertionOptions = {},\n): string {\n assertString(value, sourceCodeInfo, options)\n return value\n}\n\nexport function isStringOrNumber(value: unknown): value is string | number {\n return typeof value === 'string' || typeof value === 'number'\n}\nexport function asStringOrNumber(value: unknown, sourceCodeInfo?: SourceCodeInfo): string | number {\n assertStringOrNumber(value, sourceCodeInfo)\n return value\n}\nexport function assertStringOrNumber(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n): asserts value is string | number {\n if (!isStringOrNumber(value))\n throw getAssertionError('string or number', value, sourceCodeInfo)\n}\n","import type { Any, Coll, Obj } from '../interface'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { asAny, isColl, isObj, isRegularExpression } from '../typeGuards/lits'\nimport { isNumber } from '../typeGuards/number'\nimport { asString, assertStringOrNumber } from '../typeGuards/string'\nimport { isUnknownRecord } from '../typeGuards'\nimport { LitsError } from '../errors'\n\nexport function collHasKey(coll: unknown, key: string | number): boolean {\n if (!isColl(coll))\n return false\n\n if (typeof coll === 'string' || Array.isArray(coll)) {\n if (!isNumber(key, { integer: true }))\n return false\n\n return key >= 0 && key < coll.length\n }\n return !!Object.getOwnPropertyDescriptor(coll, key)\n}\n\nexport function compare<T extends string | number>(a: T, b: T, sourceCodeInfo: SourceCodeInfo | undefined): number {\n assertStringOrNumber(a, sourceCodeInfo)\n assertStringOrNumber(b, sourceCodeInfo)\n\n if (typeof a === 'string' && typeof b === 'string') {\n return a < b ? -1 : a > b ? 1 : 0\n }\n if (typeof a === 'number' && typeof b === 'number') {\n return Math.sign((a) - (b))\n }\n throw new LitsError(`Cannot compare values of different types: ${typeof a} and ${typeof b}`, sourceCodeInfo)\n}\n\nexport function deepEqual(a: unknown, b: unknown, sourceCodeInfo?: SourceCodeInfo): boolean {\n if (a === b)\n return true\n\n if (typeof a === 'number' && typeof b === 'number')\n return approxEqual(a, b)\n\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length)\n return false\n\n for (let i = 0; i < a.length; i += 1) {\n if (!deepEqual(asAny(a[i], sourceCodeInfo), asAny(b[i], sourceCodeInfo), sourceCodeInfo))\n return false\n }\n return true\n }\n if (isRegularExpression(a) && isRegularExpression(b))\n return a.s === b.s && a.f === b.f\n\n if (isUnknownRecord(a) && isUnknownRecord(b)) {\n const aKeys = Object.keys(a)\n const bKeys = Object.keys(b)\n if (aKeys.length !== bKeys.length)\n return false\n\n for (let i = 0; i < aKeys.length; i += 1) {\n const key = asString(aKeys[i], sourceCodeInfo)\n if (!deepEqual(a[key], b[key], sourceCodeInfo))\n return false\n }\n return true\n }\n return false\n}\n\nexport function toNonNegativeInteger(num: number): number {\n return Math.max(0, Math.ceil(num))\n}\n\nexport function toAny(value: unknown): Any {\n return (value ?? null) as Any\n}\n\nfunction clone<T>(value: T): T {\n if (isObj(value)) {\n return Object.entries(value).reduce((result: Obj, entry) => {\n const [key, val] = entry\n result[key] = clone(val)\n return result\n }, {}) as T\n }\n if (Array.isArray(value))\n // eslint-disable-next-line ts/no-unsafe-return\n return value.map(item => clone(item)) as unknown as T\n\n return value\n}\n\nexport function cloneColl<T extends Coll>(value: T): T {\n return clone(value)\n}\n\nexport function joinSets<T>(...results: Set<T>[]): Set<T> {\n const result = new Set<T>()\n for (const symbols of results)\n symbols.forEach(symbol => result.add(symbol))\n\n return result\n}\n\nexport function addToSet<T>(target: Set<T>, source: Set<T>): void {\n source.forEach(symbol => target.add(symbol))\n}\n\nexport const EPSILON = 1e-10\n\nexport function approxEqual(a: number, b: number, epsilon: number = EPSILON): boolean {\n if (a === b) {\n return true\n }\n\n const diff = Math.abs(a - b)\n\n if (a === 0 || b === 0 || diff < epsilon) {\n // Use absolute error for values near zero\n return diff < epsilon\n }\n const absA = Math.abs(a)\n const absB = Math.abs(b)\n\n // Use relative error for larger values\n return diff / (absA + absB) < epsilon\n}\n\nexport function approxZero(value: number): boolean {\n return Math.abs(value) < EPSILON\n}\n\nexport function smartTrim(str: string, minIndent = 0): string {\n const lines = str.split('\\n')\n while (lines[0]?.match(/^\\s*$/)) {\n lines.shift() // Remove leading empty lines\n }\n while (lines[lines.length - 1]?.match(/^\\s*$/)) {\n lines.pop() // Remove trailing empty lines\n }\n const indent = lines.reduce((acc, line) => {\n if (line.match(/^\\s*$/))\n return acc // Skip empty lines\n const lineIndent = line.match(/^\\s*/)![0].length\n return Math.min(acc, lineIndent)\n }, Infinity)\n return lines.map(line => ' '.repeat(minIndent) + line.slice(indent)).join('\\n').trimEnd()\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 { Any, Arr, Obj, Seq } from '../../../interface'\nimport type { SourceCodeInfo } from '../../../tokenizer/token'\nimport { asArray, assertArray, assertCharArray } from '../../../typeGuards/array'\nimport { asAny, asSeq, assertAny, assertFunctionLike, assertSeq } from '../../../typeGuards/lits'\nimport { asNumber, assertNumber } from '../../../typeGuards/number'\nimport { assertString, assertStringOrNumber } from '../../../typeGuards/string'\nimport { collHasKey, compare, deepEqual, toNonNegativeInteger } from '../../../utils'\nimport { toFixedArity } from '../../../utils/arity'\nimport type { BuiltinNormalExpressions } from '../../interface'\nimport type { LitsModule } from '../interface'\n\nconst sequenceUtilsFunctions: BuiltinNormalExpressions = {\n 'position': {\n evaluate: ([seq, fn]: Arr, sourceCodeInfo, contextStack, { executeFunction }): number | null => {\n assertFunctionLike(fn, sourceCodeInfo)\n if (seq === null)\n return null\n\n assertSeq(seq, sourceCodeInfo)\n if (typeof seq === 'string') {\n const index = seq.split('').findIndex(elem => executeFunction(fn, [elem], contextStack, sourceCodeInfo))\n return index !== -1 ? index : null\n }\n else {\n const index = seq.findIndex(elem => executeFunction(fn, [elem], contextStack, sourceCodeInfo))\n return index !== -1 ? index : null\n }\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: ['number', 'null'] },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: ['sequence', 'null'] },\n fun: { type: 'function' },\n },\n variants: [{ argumentNames: ['seq', 'fun'] }],\n description: 'Returns the index of the first elements that passes the test implemented by $fun. If no element was found, `null` is returned.',\n seeAlso: ['index-of', 'some', 'find'],\n examples: [\n `\nlet su = import(\"sequence\");\nsu.position(\n [\"Albert\", \"Mojir\", 160, [1, 2]],\n string?\n)`,\n `\nlet su = import(\"sequence\");\nsu.position(\n [5, 10, 15, 20],\n -> $ > 10\n)`,\n `\nlet su = import(\"sequence\");\nsu.position(\n [5, 10, 15, 20],\n -> $ > 100\n)`,\n `\nlet su = import(\"sequence\");\nsu.position(\n null,\n -> $ > 100\n)`,\n ],\n },\n },\n 'last-index-of': {\n evaluate: ([seq, value], sourceCodeInfo): number | null => {\n assertAny(value, sourceCodeInfo)\n if (seq === null)\n return null\n\n assertSeq(seq, sourceCodeInfo)\n if (typeof seq === 'string') {\n assertString(value, sourceCodeInfo)\n const index = seq.lastIndexOf(value)\n return index !== -1 ? index : null\n }\n else {\n const index = seq.findLastIndex(item => deepEqual(asAny(item, sourceCodeInfo), value), sourceCodeInfo)\n return index !== -1 ? index : null\n }\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: ['number', 'null'] },\n args: {\n a: { type: 'sequence' },\n b: { type: 'any' },\n seq: { type: ['sequence', 'null'] },\n x: { type: 'any' },\n },\n variants: [{ argumentNames: ['seq', 'x'] }],\n description: 'Returns the last index of $x in $seq. If element is not present in $seq `null` is returned.',\n seeAlso: ['index-of'],\n examples: [\n 'let su = import(\"sequence\"); su.last-index-of([[1], [2], [1], [2]], [1])',\n 'let su = import(\"sequence\"); su.last-index-of([\"Albert\", \"Mojir\", 160, [1, 2]], \"Mojir\")',\n 'let su = import(\"sequence\"); su.last-index-of([5, 10, 15, 20, 15], 15)',\n 'let su = import(\"sequence\"); su.last-index-of([5, 10, 15, 20], 1)',\n 'let su = import(\"sequence\"); su.last-index-of(null, 1)',\n ],\n },\n },\n 'shift': {\n evaluate: ([seq], sourceCodeInfo): Any => {\n assertSeq(seq, sourceCodeInfo)\n if (typeof seq === 'string')\n return seq.substring(1)\n\n const copy = [...seq]\n copy.shift()\n return copy\n },\n arity: toFixedArity(1),\n docs: {\n category: 'sequence',\n returns: { type: ['sequence', 'null'] },\n args: { seq: { type: 'sequence' } },\n variants: [{ argumentNames: ['seq'] }],\n description: 'Returns a copy of $seq with first element removed. If $seq is empty `null` is returned.',\n seeAlso: ['sequence.unshift', 'pop', 'rest'],\n examples: [\n 'let su = import(\"sequence\"); su.shift([1, 2, 3])',\n 'let su = import(\"sequence\"); su.shift([])',\n ],\n },\n },\n 'splice': {\n evaluate: (params, sourceCodeInfo): Any => {\n const [seq, start, deleteCount, ...rest] = params\n assertSeq(seq, sourceCodeInfo)\n assertNumber(start, sourceCodeInfo, { integer: true })\n assertNumber(deleteCount, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const from = start < 0 ? seq.length + start : start\n\n if (Array.isArray(seq)) {\n return [...seq.slice(0, from), ...rest, ...seq.slice(from + deleteCount)]\n }\n\n rest.forEach(elem => assertString(elem, sourceCodeInfo))\n return `${seq.substring(0, from)}${rest.join('')}${seq.substring(from + deleteCount)}`\n },\n arity: { min: 3 },\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n seq: { type: 'sequence', rest: true },\n start: { type: 'integer' },\n deleteCount: { type: 'integer' },\n items: { type: 'any', rest: true },\n },\n variants: [\n { argumentNames: ['seq', 'start', 'deleteCount'] },\n { argumentNames: ['seq', 'start', 'deleteCount', 'items'] },\n ],\n description: 'Returns a a spliced array. Removes $deleteCount elements from $seq starting at $start and replaces them with $items. If $start is negative, it is counting from the end of the array.',\n seeAlso: ['slice', 'sequence.remove-at'],\n examples: [\n 'let su = import(\"sequence\"); su.splice([1, 2, 3, 4, 5], 2, 2, \"x\")',\n 'let su = import(\"sequence\"); su.splice([1, 2, 3, 4, 5], -2, 1, \"x\")',\n 'let su = import(\"sequence\"); su.splice(\"Albert\", 2, 2, \"fo\")',\n ],\n },\n },\n 'sort-by': {\n evaluate: (params: Arr, sourceCodeInfo, contextStack, { executeFunction }): Seq => {\n const [seq, keyfn] = params\n const defaultComparer = params.length === 2\n\n assertSeq(seq, sourceCodeInfo)\n assertFunctionLike(keyfn, sourceCodeInfo)\n const comparer = defaultComparer ? null : params[2]\n\n if (typeof seq === 'string') {\n const result = seq.split('')\n if (defaultComparer) {\n result.sort((a, b) => {\n const aKey = executeFunction(keyfn, [a], contextStack, sourceCodeInfo)\n assertStringOrNumber(aKey, sourceCodeInfo)\n const bKey = executeFunction(keyfn, [b], contextStack, sourceCodeInfo)\n assertStringOrNumber(bKey, sourceCodeInfo)\n return compare(aKey, bKey, sourceCodeInfo)\n })\n }\n else {\n assertFunctionLike(comparer, sourceCodeInfo)\n result.sort((a, b) => {\n const aKey = executeFunction(keyfn, [a], contextStack, sourceCodeInfo)\n const bKey = executeFunction(keyfn, [b], contextStack, sourceCodeInfo)\n const compareValue = executeFunction(comparer, [aKey, bKey], contextStack, sourceCodeInfo)\n assertNumber(compareValue, sourceCodeInfo, { finite: true })\n return compareValue\n })\n }\n return result.join('')\n }\n\n const result = [...seq]\n if (defaultComparer) {\n result.sort((a, b) => {\n const aKey = executeFunction(keyfn, [a], contextStack, sourceCodeInfo)\n assertStringOrNumber(aKey, sourceCodeInfo)\n const bKey = executeFunction(keyfn, [b], contextStack, sourceCodeInfo)\n assertStringOrNumber(bKey, sourceCodeInfo)\n return compare(aKey, bKey, sourceCodeInfo)\n })\n }\n else {\n assertFunctionLike(comparer, sourceCodeInfo)\n result.sort((a, b) => {\n const aKey = executeFunction(keyfn, [a], contextStack, sourceCodeInfo)\n const bKey = executeFunction(keyfn, [b], contextStack, sourceCodeInfo)\n const compareValue = executeFunction(comparer, [aKey, bKey], contextStack, sourceCodeInfo)\n assertNumber(compareValue, sourceCodeInfo, { finite: true })\n return compareValue\n })\n }\n return result\n },\n arity: { min: 2, max: 3 },\n docs: {\n category: 'sequence',\n returns: { type: 'any', rest: true },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: 'sequence' },\n keyfn: { type: 'function' },\n comparer: { type: 'function' },\n },\n variants: [\n { argumentNames: ['seq', 'keyfn'] },\n { argumentNames: ['seq', 'keyfn', 'comparer'] },\n ],\n description: 'Returns a sorted sequence of the items in $seq, where the sort order is determined by comparing `(keyfn item)`. If no $comparer is supplied, uses builtin `compare`.',\n seeAlso: ['sort', 'compare'],\n examples: [\n 'let su = import(\"sequence\"); su.sort-by([\"Albert\", \"Mojir\", \"Nina\"], count)',\n 'let su = import(\"sequence\"); su.sort-by([\"Albert\", \"Mojir\", \"Nina\"], count)',\n 'let su = import(\"sequence\"); su.sort-by(\"Albert\", lower-case, -> $2 compare $1)',\n ],\n },\n },\n 'take': {\n evaluate: ([input, n], sourceCodeInfo): Seq => {\n assertNumber(n, sourceCodeInfo)\n assertSeq(input, sourceCodeInfo)\n const num = Math.max(Math.ceil(n), 0)\n return input.slice(0, num)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'integer' },\n n: { type: 'integer' },\n seq: { type: 'sequence' },\n },\n variants: [{ argumentNames: ['seq', 'n'] }],\n description: 'Constructs a new array/string with the $n first elements from $seq.',\n seeAlso: ['sequence.take-last', 'sequence.take-while', 'sequence.drop', 'slice', 'sequence.split-at'],\n examples: [\n 'let su = import(\"sequence\"); su.take([1, 2, 3, 4, 5], 3)',\n 'let su = import(\"sequence\"); su.take([1, 2, 3, 4, 5], 3)',\n 'let su = import(\"sequence\"); su.take([1, 2, 3, 4, 5], 0)',\n 'let su = import(\"sequence\"); su.take(\"Albert\", 2)',\n 'let su = import(\"sequence\"); su.take(\"Albert\", 50)',\n ],\n },\n },\n 'take-last': {\n evaluate: ([array, n], sourceCodeInfo): Seq => {\n assertSeq(array, sourceCodeInfo)\n assertNumber(n, sourceCodeInfo)\n const num = Math.max(Math.ceil(n), 0)\n const from = array.length - num\n return array.slice(from)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'integer' },\n n: { type: 'integer' },\n seq: { type: 'sequence' },\n },\n variants: [{ argumentNames: ['n', 'seq'] }],\n description: 'Constructs a new array with the $n last elements from $seq.',\n seeAlso: ['sequence.take', 'sequence.drop-last'],\n examples: [\n 'let su = import(\"sequence\"); su.take-last([1, 2, 3, 4, 5], 3)',\n 'let su = import(\"sequence\"); su.take-last([1, 2, 3, 4, 5], 3)',\n 'let su = import(\"sequence\"); su.take-last([1, 2, 3, 4, 5], 0)',\n ],\n },\n },\n 'take-while': {\n evaluate: ([seq, fn]: Arr, sourceCodeInfo, contextStack, { executeFunction }): Any => {\n assertSeq(seq, sourceCodeInfo)\n assertFunctionLike(fn, sourceCodeInfo)\n\n const result: Arr = []\n for (const item of seq) {\n if (executeFunction(fn, [item], contextStack, sourceCodeInfo))\n result.push(item)\n else\n break\n }\n return typeof seq === 'string' ? result.join('') : result\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: 'sequence' },\n fun: { type: 'function' },\n },\n variants: [{ argumentNames: ['seq', 'fun'] }],\n description: 'Returns the members of $seq in order, stopping before the first one for which `predicate` returns a falsy value.',\n seeAlso: ['sequence.take', 'sequence.drop-while', 'sequence.split-with'],\n examples: [\n `\nlet su = import(\"sequence\");\nsu.take-while(\n [1, 2, 3, 2, 1],\n -> $ < 3\n)`,\n `\nlet su = import(\"sequence\");\nsu.take-while(\n [1, 2, 3, 2, 1],\n -> $ > 3\n)`,\n ],\n },\n },\n 'drop': {\n evaluate: ([input, n], sourceCodeInfo): Seq => {\n assertNumber(n, sourceCodeInfo)\n const num = Math.max(Math.ceil(n), 0)\n assertSeq(input, sourceCodeInfo)\n return input.slice(num)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'integer' },\n seq: { type: 'sequence' },\n n: { type: 'integer' },\n },\n variants: [{ argumentNames: ['seq', 'n'] }],\n description: 'Constructs a new array/string with the $n first elements dropped from $seq.',\n seeAlso: ['sequence.drop-last', 'sequence.drop-while', 'sequence.take', 'slice', 'sequence.split-at'],\n examples: [\n 'let su = import(\"sequence\"); su.drop([1, 2, 3, 4, 5], 3)',\n 'let su = import(\"sequence\"); su.drop([1, 2, 3, 4, 5], 0)',\n 'let su = import(\"sequence\"); su.drop(\"Albert\", 2)',\n 'let su = import(\"sequence\"); su.drop(\"Albert\", 50)',\n ],\n },\n },\n 'drop-last': {\n evaluate: ([array, n], sourceCodeInfo): Seq => {\n assertSeq(array, sourceCodeInfo)\n assertNumber(n, sourceCodeInfo)\n const num = Math.max(Math.ceil(n), 0)\n\n const from = array.length - num\n return array.slice(0, from)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'integer' },\n seq: { type: 'sequence' },\n n: { type: 'integer' },\n },\n variants: [{ argumentNames: ['seq', 'n'] }],\n description: 'Constructs a new array with the $n last elements dropped from $seq.',\n seeAlso: ['sequence.drop', 'sequence.take-last'],\n examples: [\n 'let su = import(\"sequence\"); su.drop-last([1, 2, 3, 4, 5], 3)',\n 'let su = import(\"sequence\"); su.drop-last([1, 2, 3, 4, 5], 3)',\n 'let su = import(\"sequence\"); su.drop-last([1, 2, 3, 4, 5], 0)',\n ],\n },\n },\n 'drop-while': {\n evaluate: ([seq, fn]: Arr, sourceCodeInfo, contextStack, { executeFunction }): Any => {\n assertSeq(seq, sourceCodeInfo)\n assertFunctionLike(fn, sourceCodeInfo)\n\n if (Array.isArray(seq)) {\n const from = seq.findIndex(elem => !executeFunction(fn, [elem], contextStack, sourceCodeInfo))\n return seq.slice(from)\n }\n const charArray = seq.split('')\n const from = charArray.findIndex(elem => !executeFunction(fn, [elem], contextStack, sourceCodeInfo))\n return charArray.slice(from).join('')\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: 'sequence' },\n fun: { type: 'function' },\n },\n variants: [{ argumentNames: ['seq', 'fun'] }],\n description: 'Returns the members of $seq in order, skipping the fist elements for witch the `predicate` returns a truethy value.',\n seeAlso: ['sequence.drop', 'sequence.take-while', 'sequence.split-with'],\n examples: [\n `\nlet su = import(\"sequence\");\nsu.drop-while(\n [1, 2, 3, 2, 1],\n -> $ < 3\n)`,\n `\nlet su = import(\"sequence\");\nsu.drop-while(\n [1, 2, 3, 2, 1],\n -> $ > 3\n)`,\n ],\n },\n },\n 'unshift': {\n evaluate: ([seq, ...values], sourceCodeInfo): Seq => {\n assertSeq(seq, sourceCodeInfo)\n if (typeof seq === 'string') {\n assertCharArray(values, sourceCodeInfo)\n return [...values, seq].join('')\n }\n const copy = [...seq]\n copy.unshift(...values)\n return copy\n },\n arity: { min: 2 },\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'any' },\n seq: { type: 'sequence' },\n values: { type: 'any', rest: true },\n },\n variants: [{ argumentNames: ['seq', 'values'] }],\n description: 'Returns copy of $seq with $values added to the beginning.',\n seeAlso: ['push', 'sequence.shift', '++'],\n examples: [\n 'let su = import(\"sequence\"); su.unshift([1, 2, 3], 4)',\n 'let su = import(\"sequence\"); su.unshift([1, 2, 3], 4)',\n 'let su = import(\"sequence\"); su.unshift([1, 2, 3], 4, 5, 6)',\n `\nlet su = import(\"sequence\");\nlet l = [1, 2, 3];\nsu.unshift(l, 4);\nl`,\n ],\n },\n },\n 'distinct': {\n evaluate: ([input], sourceCodeInfo): Seq => {\n assertSeq(input, sourceCodeInfo)\n\n if (Array.isArray(input)) {\n const result: Any[] = []\n for (const item of input) {\n assertAny(item, sourceCodeInfo)\n if (!result.some(existingItem => deepEqual(existingItem, item, sourceCodeInfo))) {\n result.push(item)\n }\n }\n return result\n }\n\n return Array.from(new Set(input.split(''))).join('')\n },\n arity: toFixedArity(1),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: { seq: { type: 'sequence' } },\n variants: [{ argumentNames: ['seq'] }],\n description: 'Returns a copy of $seq with no duplicates.',\n seeAlso: ['sequence.frequencies'],\n examples: [\n 'let su = import(\"sequence\"); su.distinct([[1], [2], [3], [1], [3], [5]])',\n 'let su = import(\"sequence\"); su.distinct([1, 2, 3, 1, 3, 5])',\n 'let su = import(\"sequence\"); su.distinct(\"Albert Mojir\")',\n 'let su = import(\"sequence\"); su.distinct([])',\n 'let su = import(\"sequence\"); su.distinct(\"\")',\n ],\n },\n },\n 'remove': {\n evaluate: ([input, fn], sourceCodeInfo, contextStack, { executeFunction }): Seq => {\n assertFunctionLike(fn, sourceCodeInfo)\n assertSeq(input, sourceCodeInfo)\n if (Array.isArray(input))\n return input.filter(elem => !executeFunction(fn, [elem], contextStack, sourceCodeInfo))\n\n return input\n .split('')\n .filter(elem => !executeFunction(fn, [elem], contextStack, sourceCodeInfo))\n .join('')\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: 'sequence' },\n fun: { type: 'function' },\n },\n variants: [{ argumentNames: ['seq', 'fun'] }],\n description: 'Returns a new sequence of items in $seq for witch `pred(item)` returns a falsy value.',\n seeAlso: ['filter', 'sequence.remove-at'],\n examples: [\n 'let su = import(\"sequence\"); su.remove([1, 2, 3, 1, 3, 5], odd?)',\n 'let su = import(\"sequence\"); su.remove([1, 2, 3, 1, 3, 5], even?)',\n 'let su = import(\"sequence\"); su.remove(\"Albert Mojir\", -> \"aoueiyAOUEIY\" contains? $)',\n ],\n },\n },\n 'remove-at': {\n evaluate: ([input, index], sourceCodeInfo): Seq => {\n assertNumber(index, sourceCodeInfo, { integer: true })\n assertSeq(input, sourceCodeInfo)\n\n const at = index < 0 ? input.length + index : index\n if (at < 0 || at >= input.length)\n return input\n\n if (Array.isArray(input)) {\n return input.filter((_, i) => i !== at)\n }\n return `${input.substring(0, at)}${input.substring(at + 1)}`\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'integer' },\n seq: { type: 'sequence' },\n n: { type: 'number' },\n },\n variants: [{ argumentNames: ['seq', 'n'] }],\n description: 'Returns a new sequence of all items in $seq except item at position $n. If $n is negative, it is counting from the end of the sequence.',\n seeAlso: ['sequence.remove', 'sequence.splice'],\n examples: [\n 'let su = import(\"sequence\"); su.remove-at([1, 2, 3, 1, 3, 5], 2)',\n 'let su = import(\"sequence\"); su.remove-at(\"Albert\", -2)',\n 'let su = import(\"sequence\"); su.remove-at([1, 2, 3, 1, 3, 5], 0)',\n 'let su = import(\"sequence\"); su.remove-at([1, 2, 3, 1, 3, 5], -1)',\n 'let su = import(\"sequence\"); su.remove-at(\"Albert Mojir\", 6)',\n ],\n },\n },\n 'split-at': {\n evaluate: ([seq, pos], sourceCodeInfo): Seq => {\n assertNumber(pos, sourceCodeInfo, { integer: true })\n assertSeq(seq, sourceCodeInfo)\n\n const at = pos < 0 ? seq.length + pos : pos\n return [seq.slice(0, at), seq.slice(at)]\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'integer' },\n seq: { type: 'sequence' },\n n: { type: 'number' },\n },\n variants: [{ argumentNames: ['seq', 'n'] }],\n description: 'Returns a pair of sequence `[take(pos input), drop(pos input)]`.',\n seeAlso: ['sequence.split-with', 'sequence.take', 'sequence.drop'],\n examples: [\n 'let su = import(\"sequence\"); su.split-at([1, 2, 3, 4, 5], 2)',\n 'let su = import(\"sequence\"); su.split-at(\"Albert\", -2)',\n 'let su = import(\"sequence\"); su.split-at([1, 2, 3, 4, 5], -2)',\n 'let su = import(\"sequence\"); su.split-at(\"Albert\", 2)',\n ],\n },\n },\n\n 'split-with': {\n evaluate: ([seq, fn], sourceCodeInfo, contextStack, { executeFunction }): Seq => {\n assertFunctionLike(fn, sourceCodeInfo)\n assertSeq(seq, sourceCodeInfo)\n const seqIsArray = Array.isArray(seq)\n const arr = seqIsArray ? seq : seq.split('')\n const index = arr.findIndex(elem => !executeFunction(fn, [elem], contextStack, sourceCodeInfo))\n if (index === -1)\n return [seq, seqIsArray ? [] : '']\n\n return [seq.slice(0, index), seq.slice(index)]\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: 'sequence' },\n fun: { type: 'function' },\n },\n variants: [{ argumentNames: ['seq', 'fun'] }],\n description: 'Returns a pair of sequences `[take-while(input, fun), drop-while(input, fun)]`.',\n seeAlso: ['sequence.split-at', 'sequence.take-while', 'sequence.drop-while'],\n examples: [\n 'let su = import(\"sequence\"); su.split-with([1, 2, 3, 4, 5], odd?)',\n 'let su = import(\"sequence\"); su.split-with([1, 2, 3, 4, 5], -> $ > 3)',\n 'let su = import(\"sequence\"); su.split-with(\"Albert\", -> $ <= \"o\")',\n ],\n },\n },\n\n 'frequencies': {\n evaluate: ([seq], sourceCodeInfo): Obj => {\n assertSeq(seq, sourceCodeInfo)\n\n const arr = typeof seq === 'string' ? seq.split('') : seq\n\n return arr.reduce((result: Obj, val) => {\n assertString(val, sourceCodeInfo)\n if (collHasKey(result, val))\n result[val] = (result[val] as number) + 1\n else\n result[val] = 1\n\n return result\n }, {})\n },\n arity: toFixedArity(1),\n docs: {\n category: 'sequence',\n returns: { type: 'object' },\n args: { seq: { type: 'sequence' } },\n variants: [{ argumentNames: ['seq'] }],\n description: 'Returns an object from distinct items in $seq to the number of times they appear. Note that all items in $seq must be valid object keys i.e. strings.',\n seeAlso: ['sequence.group-by', 'sequence.distinct', 'vector.count-values'],\n examples: [\n 'let su = import(\"sequence\"); su.frequencies([\"Albert\", \"Mojir\", \"Nina\", \"Mojir\"])',\n 'let su = import(\"sequence\"); su.frequencies(\"Pneumonoultramicroscopicsilicovolcanoconiosis\")',\n ],\n },\n },\n\n 'group-by': {\n evaluate: ([seq, fn], sourceCodeInfo, contextStack, { executeFunction }): Obj => {\n assertFunctionLike(fn, sourceCodeInfo)\n assertSeq(seq, sourceCodeInfo)\n const arr = Array.isArray(seq) ? seq : seq.split('')\n\n return arr.reduce((result: Obj, val) => {\n const key = executeFunction(fn, [val], contextStack, sourceCodeInfo)\n assertString(key, sourceCodeInfo)\n if (!collHasKey(result, key))\n result[key] = []\n\n ;(result[key] as Arr).push(val)\n return result\n }, {})\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'object' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: 'sequence' },\n fun: { type: 'function' },\n },\n variants: [{ argumentNames: ['seq', 'fun'] }],\n description: 'Returns an object of the elements of $seq keyed by the result of $fun on each element. The value at each key will be an array of the corresponding elements.',\n seeAlso: ['sequence.frequencies', 'sequence.partition-by'],\n examples: [\n 'let su = import(\"sequence\"); su.group-by([{ name: \"Albert\" }, { name: \"Albert\" }, { name: \"Mojir\" }], \"name\")',\n 'let su = import(\"sequence\"); su.group-by([{name: \"Albert\"}, {name: \"Albert\"}, {name: \"Mojir\"}], \"name\")',\n 'let su = import(\"sequence\"); su.group-by(\"Albert Mojir\", -> \"aoueiAOUEI\" contains? $ ? \"vowel\" : \"other\")',\n ],\n },\n },\n\n 'partition': {\n evaluate: (params, sourceCodeInfo): Seq => {\n const seq = asSeq(params[0], sourceCodeInfo)\n const n = toNonNegativeInteger(asNumber(params[1], sourceCodeInfo))\n const step = params.length >= 3 ? toNonNegativeInteger(asNumber(params[2], sourceCodeInfo)) : n\n const pad = params.length === 4\n ? params[3] === null ? [] : asArray(params[3], sourceCodeInfo)\n : undefined\n\n return partitionHelper(n, step, seq, pad, sourceCodeInfo)\n },\n arity: { min: 2, max: 4 },\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'number' },\n seq: { type: 'sequence' },\n n: { type: 'number' },\n step: { type: 'number' },\n pad: { type: 'array' },\n },\n variants: [\n { argumentNames: ['seq', 'n'] },\n { argumentNames: ['seq', 'n', 'step'] },\n { argumentNames: ['seq', 'n', 'step', 'pad'] },\n ],\n description: 'Returns an array of sequences of $n items each, at offsets $step apart. If $step is not supplied, defaults to $n. If a $pad array is supplied, use its elements as necessary to complete last partition upto $n items. In case there are not enough padding elements, return a partition with less than $n items.',\n seeAlso: ['sequence.partition-all', 'sequence.partition-by'],\n examples: [\n 'let su = import(\"sequence\"); su.partition(range(20), 4)',\n 'let su = import(\"sequence\"); su.partition(range(20), 4)',\n 'let su = import(\"sequence\"); su.partition(range(22), 4)',\n 'let su = import(\"sequence\"); su.partition(range(20), 4, 6)',\n 'let su = import(\"sequence\"); su.partition(range(20), 4, 3)',\n 'let su = import(\"sequence\"); su.partition(range(20), 3, 6, [\"a\"])',\n 'let su = import(\"sequence\"); su.partition(range(20), 4, 6, [\"a\"])',\n 'let su = import(\"sequence\"); su.partition(range(20), 4, 6, [\"a\", \"b\", \"c\", \"d\"])',\n 'let su = import(\"sequence\"); su.partition([\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"], 3, 1)',\n 'let su = import(\"sequence\"); su.partition([1, 2, 3, 4], 10)',\n 'let su = import(\"sequence\"); su.partition([1, 2, 3, 4], 10, 10)',\n 'let su = import(\"sequence\"); su.partition([1, 2, 3, 4], 10, 10, [])',\n 'let su = import(\"sequence\"); su.partition([1, 2, 3, 4], 10, 10, null)',\n 'let su = import(\"sequence\"); su.partition(\"superfragilistic\", 5)',\n 'let su = import(\"sequence\"); su.partition(\"superfragilistic\", 5, 5, null)',\n 'let su = import(\"sequence\"); let foo = [5, 6, 7, 8]; su.partition(foo, 2, 1, foo)',\n ],\n },\n },\n\n 'partition-all': {\n evaluate: (params, sourceCodeInfo): Seq => {\n const seq = asSeq(params[0], sourceCodeInfo)\n const n = toNonNegativeInteger(asNumber(params[1], sourceCodeInfo))\n const step = params.length === 3 ? toNonNegativeInteger(asNumber(params[2], sourceCodeInfo)) : n\n\n return partitionHelper(n, step, seq, [], sourceCodeInfo)\n },\n arity: { min: 2, max: 3 },\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'number' },\n seq: { type: 'sequence' },\n n: { type: 'number' },\n step: { type: 'number' },\n },\n variants: [\n { argumentNames: ['seq', 'n'] },\n { argumentNames: ['seq', 'n', 'step'] },\n ],\n description: 'Returns an array of sequences like partition, but may include partitions with fewer than n items at the end.',\n seeAlso: ['sequence.partition', 'sequence.partition-by'],\n examples: [\n 'let su = import(\"sequence\"); su.partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)',\n 'let su = import(\"sequence\"); su.partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)',\n 'let su = import(\"sequence\"); su.partition([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)',\n 'let su = import(\"sequence\"); su.partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 2, 4)',\n ],\n },\n },\n\n 'partition-by': {\n evaluate: ([seq, fn], sourceCodeInfo, contextStack, { executeFunction }): Seq => {\n assertFunctionLike(fn, sourceCodeInfo)\n assertSeq(seq, sourceCodeInfo)\n const isStringSeq = typeof seq === 'string'\n let oldValue: unknown\n\n const result = (isStringSeq ? seq.split('') : seq).reduce((acc: Arr, elem) => {\n const value = executeFunction(fn, [elem], contextStack, sourceCodeInfo)\n if (value !== oldValue) {\n acc.push([])\n oldValue = value\n }\n ;(acc[acc.length - 1] as Arr).push(elem)\n return acc\n }, [])\n\n return isStringSeq ? result.map(elem => (elem as Arr).join('')) : result\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: 'sequence' },\n fun: { type: 'function' },\n },\n variants: [{ argumentNames: ['seq', 'fun'] }],\n description: 'Applies $fun to each value in $seq, splitting it each time $fun returns a new value. Returns an array of sequences.',\n seeAlso: ['sequence.partition', 'sequence.partition-all', 'sequence.group-by'],\n examples: [\n 'let su = import(\"sequence\"); su.partition-by([1, 2, 3, 4, 5], odd?)',\n 'let su = import(\"sequence\"); su.partition-by([1, 2, 3, 4, 5], -> $ == 3)',\n 'let su = import(\"sequence\"); su.partition-by([1, 1, 1, 2, 2, 3, 3], odd?)',\n 'let su = import(\"sequence\"); su.partition-by(\"Leeeeeerrroyyy\", identity)',\n ],\n },\n },\n 'ends-with?': {\n evaluate: ([str, search], sourceCodeInfo): boolean => {\n assertSeq(str, sourceCodeInfo)\n\n if (typeof str === 'string') {\n assertString(search, sourceCodeInfo)\n return str.endsWith(search)\n }\n\n return deepEqual(asAny(str.at(-1), sourceCodeInfo), asAny(search, sourceCodeInfo), sourceCodeInfo)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'boolean' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'sequence' },\n seq: { type: 'sequence' },\n suffix: { type: 'sequence' },\n },\n variants: [{ argumentNames: ['seq', 'suffix'] }],\n description: 'Returns `true` if $seq ends with $suffix, otherwise `false`.',\n seeAlso: ['sequence.starts-with?'],\n examples: [\n 'let su = import(\"sequence\"); su.ends-with?([[1], [2], [3], [4], [5]], [5])',\n 'let su = import(\"sequence\"); su.ends-with?([[1], [2], [3], [4], [5]], 5)',\n 'let su = import(\"sequence\"); su.ends-with?([1, 2, 3, 4, 5], 5)',\n 'let su = import(\"sequence\"); su.ends-with?([1, 2, 3, 4, 5], [5])',\n 'let su = import(\"sequence\"); su.ends-with?(\"Albert\", \"rt\")',\n 'let su = import(\"sequence\"); su.ends-with?(\"Albert\", \"RT\")',\n ],\n },\n },\n 'starts-with?': {\n evaluate: ([seq, search], sourceCodeInfo): boolean => {\n assertSeq(seq, sourceCodeInfo)\n\n if (typeof seq === 'string') {\n assertString(search, sourceCodeInfo)\n return seq.startsWith(search)\n }\n\n return deepEqual(asAny(seq[0], sourceCodeInfo), asAny(search, sourceCodeInfo), sourceCodeInfo)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'boolean' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'sequence' },\n seq: { type: 'sequence' },\n prefix: { type: 'sequence' },\n },\n variants: [{ argumentNames: ['seq', 'prefix'] }],\n description: 'Returns `true` if $seq starts with $prefix, otherwise `false`.',\n seeAlso: ['sequence.ends-with?'],\n examples: [\n 'let su = import(\"sequence\"); su.starts-with?([[1], [2], [3], [4], [5]], [1])',\n 'let su = import(\"sequence\"); su.starts-with?([1, 2, 3, 4, 5], 1)',\n 'let su = import(\"sequence\"); su.starts-with?([1, 2, 3, 4, 5], [1])',\n 'let su = import(\"sequence\"); su.starts-with?(\"Albert\", \"Al\")',\n 'let su = import(\"sequence\"); su.starts-with?(\"Albert\", \"al\")',\n ],\n },\n },\n 'interleave': {\n evaluate: ([...seqs], sourceCodeInfo): Seq => {\n const isStringSeq = typeof seqs[0] === 'string'\n\n const seqsArr = isStringSeq\n ? seqs.map((seq) => {\n assertString(seq, sourceCodeInfo)\n return seq.split('')\n })\n : seqs.map((seq) => {\n assertArray(seq, sourceCodeInfo)\n return seq\n })\n\n const maxLength = Math.min(...seqsArr.map(seq => seq.length))\n const result: Arr = []\n for (let i = 0; i < maxLength; i += 1) {\n for (const seq of seqsArr) {\n if (i < seq.length)\n result.push(seq[i])\n }\n }\n return isStringSeq ? result.join('') : result\n },\n arity: { min: 1 },\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'sequence' },\n seqs: { type: 'sequence', rest: true },\n },\n variants: [{ argumentNames: ['seqs'] }],\n description: 'Returns a sequence of the first item from each of the $seqs, then the second item from each of the $seqs, until all items from the shortest seq are exhausted.',\n seeAlso: ['sequence.interpose', 'zipmap'],\n examples: [\n 'let su = import(\"sequence\"); su.interleave([1, 2, 3], [4, 5, 6])',\n 'let su = import(\"sequence\"); su.interleave(\"Albert\", \".,.,.,\")',\n 'let su = import(\"sequence\"); su.interleave([1, 2, 3], [4, 5, 6])',\n 'let su = import(\"sequence\"); su.interleave([1, 2, 3], [4, 5, 6], [7, 8, 9])',\n 'let su = import(\"sequence\"); su.interleave([1, 2, 3], [4, 5, 6], [7, 8])',\n 'let su = import(\"sequence\"); su.interleave([1, 2, 3], [4, 5, 6], [7])',\n 'let su = import(\"sequence\"); su.interleave([1, 2, 3], [4, 5, 6], [])',\n 'let su = import(\"sequence\"); su.interleave([1, 2, 3], [])',\n 'let su = import(\"sequence\"); su.interleave([])',\n ],\n },\n },\n 'interpose': {\n evaluate: ([seq, separator], sourceCodeInfo): Seq => {\n assertSeq(seq, sourceCodeInfo)\n if (typeof seq === 'string') {\n assertString(separator, sourceCodeInfo)\n return seq.split('').join(separator)\n }\n\n if (seq.length === 0)\n return []\n\n const result: Arr = []\n for (let i = 0; i < seq.length - 1; i += 1) {\n result.push(seq[i], separator)\n }\n result.push(seq[seq.length - 1])\n return result\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'any' },\n seq: { type: 'sequence' },\n separator: { type: 'any' },\n },\n variants: [{ argumentNames: ['seq', 'separator'] }],\n description: 'Returns a sequence of the elements of $seq separated by $separator. If $seq is a string, the separator must be a string.',\n seeAlso: ['sequence.interleave', 'join'],\n examples: [\n 'let su = import(\"sequence\"); su.interpose(\"Albert\", \"-\")',\n 'let su = import(\"sequence\"); su.interpose([1, 2, 3, 4, 5], \"a\")',\n 'let su = import(\"sequence\"); su.interpose([\"Albert\", \"Mojir\", \"Nina\"], \", \")',\n 'let su = import(\"sequence\"); su.interpose(\"Albert\", \".\")',\n ],\n },\n },\n}\n\nfunction partitionHelper(n: number, step: number, seq: Seq, pad: Arr | undefined, sourceCodeInfo?: SourceCodeInfo) {\n assertNumber(step, sourceCodeInfo, { positive: true })\n const isStringSeq = typeof seq === 'string'\n\n const result: Arr[] = []\n let start = 0\n outer: while (start < seq.length) {\n const innerArr: Arr = []\n for (let i = start; i < start + n; i += 1) {\n if (i >= seq.length) {\n const padIndex = i - seq.length\n if (!pad) {\n start += step\n continue outer\n }\n if (padIndex >= pad.length)\n break\n\n innerArr.push(pad[padIndex])\n }\n else {\n innerArr.push(seq[i])\n }\n }\n result.push(innerArr)\n start += step\n }\n return isStringSeq ? result.map(x => x.join('')) : result\n}\n\nexport const sequenceUtilsModule: LitsModule = {\n name: 'sequence',\n functions: sequenceUtilsFunctions,\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","isLitsFunction","func","type","functionType","has","isNode","value","Array","isArray","valueToString","keys","find","key","RegExp","toString","JSON","stringify","getSourceCodeInfo","anyValue","getAssertionError","typeName","assertArray","assertCharArray","every","v","isCharArray","isUnknownRecord","asAny","assertAny","undefined","isAny","isSeq","asSeq","assertSeq","isColl","isRegularExpression","isObj","regexp","assertFunctionLike","isFunctionLike","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","asNumber","assertString","nonEmpty","char","isString","asString","assertStringOrNumber","isStringOrNumber","collHasKey","coll","getOwnPropertyDescriptor","compare","a","b","deepEqual","epsilon","EPSILON","diff","abs","absA","absB","approxEqual","i","s","f","aKeys","bKeys","toNonNegativeInteger","num","ceil","toFixedArity","arity","min","partitionHelper","n","step","seq","pad","isStringSeq","result","start","outer","innerArr","padIndex","push","map","sequenceUtilsModule","functions","evaluate","fn","contextStack","executeFunction","index","split","findIndex","elem","docs","category","returns","args","fun","variants","argumentNames","description","seeAlso","examples","lastIndexOf","findLastIndex","item","shift","substring","copy","splice","params","deleteCount","rest","from","slice","forEach","items","keyfn","defaultComparer","comparer","sort","aKey","bKey","compareValue","take","input","array","drop","charArray","unshift","distinct","some","existingItem","remove","at","_","pos","seqIsArray","frequencies","reduce","val","partition","asArray","oldValue","acc","str","search","endsWith","suffix","startsWith","prefix","interleave","seqs","seqsArr","maxLength","interpose","separator"],"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,cAA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AG6H,GAAK,EACvCiB,EAAOK,KAAKR,EAAId,GAAIiG,GAGtB,OADAhF,EAAOK,KAAKR,EAAIA,EAAI3I,OAAS,IACtB8I,GAETR,MAAOD,EAAa,GACpB0B,KAAM,CACJC,SAAU,WACVC,QAAS,CAAE3H,KAAM,YACjB4H,KAAM,CACJ/C,EAAG,CAAE7E,KAAM,YACX8E,EAAG,CAAE9E,KAAM,OACXqG,IAAK,CAAErG,KAAM,YACbwL,UAAW,CAAExL,KAAM,QAErB8H,SAAU,CAAC,CAAEC,cAAe,CAAC,MAAO,eACpCC,YAAa,2HACbC,QAAS,CAAC,sBAAuB,QACjCC,SAAU,CACR,2DACA,kEACA,+EACA"}
|
|
1
|
+
{"version":3,"file":"sequence.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/utils/getAssertionError.ts","../../src/typeGuards/array.ts","../../src/typeGuards/index.ts","../../src/typeGuards/litsFunction.ts","../../src/typeGuards/lits.ts","../../src/typeGuards/number.ts","../../src/typeGuards/string.ts","../../src/utils/index.ts","../../src/utils/arity.ts","../../src/utils/maybePromise.ts","../../src/builtin/modules/sequence/index.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 './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 { LitsError } from '../errors'\nimport type { UnknownRecord } from '../interface'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { valueToString } from '../utils/debug/debugTools'\nimport { getSourceCodeInfo } from '../utils/debug/getSourceCodeInfo'\n\nfunction isNonUndefined<T>(value: T | undefined): value is T {\n return value !== undefined\n}\n\nexport function asNonUndefined<T>(value: T | undefined, sourceCodeInfo?: SourceCodeInfo): T {\n assertNonUndefined(value, sourceCodeInfo)\n return value\n}\n\nexport function assertNonUndefined<T>(value: T | undefined, sourceCodeInfo?: SourceCodeInfo): asserts value is T {\n if (!isNonUndefined(value))\n throw new LitsError('Unexpected undefined', getSourceCodeInfo(value, sourceCodeInfo))\n}\n\nexport function isUnknownRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\nexport function assertUnknownRecord(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is UnknownRecord {\n if (!isUnknownRecord(value)) {\n throw new LitsError(\n `Expected ${'UnknownRecord'}, got ${valueToString(value)}.`,\n getSourceCodeInfo(value, sourceCodeInfo),\n )\n }\n}\n\nexport function asUnknownRecord(value: unknown, sourceCodeInfo?: SourceCodeInfo): UnknownRecord {\n assertUnknownRecord(value, sourceCodeInfo)\n return value\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 { 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 type { SourceCodeInfo } from '../tokenizer/token'\nimport { getAssertionError } from '../utils/getAssertionError'\n\ntype StringAssertionOptions =\n | {\n nonEmpty?: true\n char?: never\n }\n | {\n nonEmpty?: never\n char?: true\n }\n\nexport function isString(value: unknown, options: StringAssertionOptions = {}): value is string {\n if (typeof value !== 'string')\n return false\n\n if (options.nonEmpty && value.length === 0)\n return false\n\n if (options.char && value.length !== 1)\n return false\n\n return true\n}\n\nexport function assertString(\n value: unknown,\n sourceCodeInfo: SourceCodeInfo | undefined,\n options: StringAssertionOptions = {},\n): asserts value is string {\n if (!isString(value, options)) {\n throw getAssertionError(\n `${options.nonEmpty ? 'non empty string' : options.char ? 'character' : 'string'}`,\n value,\n sourceCodeInfo,\n )\n }\n}\n\nexport function asString(\n value: unknown,\n sourceCodeInfo: SourceCodeInfo | undefined,\n options: StringAssertionOptions = {},\n): string {\n assertString(value, sourceCodeInfo, options)\n return value\n}\n\nexport function isStringOrNumber(value: unknown): value is string | number {\n return typeof value === 'string' || typeof value === 'number'\n}\nexport function asStringOrNumber(value: unknown, sourceCodeInfo?: SourceCodeInfo): string | number {\n assertStringOrNumber(value, sourceCodeInfo)\n return value\n}\nexport function assertStringOrNumber(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n): asserts value is string | number {\n if (!isStringOrNumber(value))\n throw getAssertionError('string or number', value, sourceCodeInfo)\n}\n","import type { Any, Coll, Obj } from '../interface'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { asAny, isColl, isObj, isRegularExpression } from '../typeGuards/lits'\nimport { isNumber } from '../typeGuards/number'\nimport { asString, assertStringOrNumber } from '../typeGuards/string'\nimport { isUnknownRecord } from '../typeGuards'\nimport { LitsError } from '../errors'\n\nexport function collHasKey(coll: unknown, key: string | number): boolean {\n if (!isColl(coll))\n return false\n\n if (typeof coll === 'string' || Array.isArray(coll)) {\n if (!isNumber(key, { integer: true }))\n return false\n\n return key >= 0 && key < coll.length\n }\n return !!Object.getOwnPropertyDescriptor(coll, key)\n}\n\nexport function compare<T extends string | number>(a: T, b: T, sourceCodeInfo: SourceCodeInfo | undefined): number {\n assertStringOrNumber(a, sourceCodeInfo)\n assertStringOrNumber(b, sourceCodeInfo)\n\n if (typeof a === 'string' && typeof b === 'string') {\n return a < b ? -1 : a > b ? 1 : 0\n }\n if (typeof a === 'number' && typeof b === 'number') {\n return Math.sign((a) - (b))\n }\n throw new LitsError(`Cannot compare values of different types: ${typeof a} and ${typeof b}`, sourceCodeInfo)\n}\n\nexport function deepEqual(a: unknown, b: unknown, sourceCodeInfo?: SourceCodeInfo): boolean {\n if (a === b)\n return true\n\n if (typeof a === 'number' && typeof b === 'number')\n return approxEqual(a, b)\n\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length)\n return false\n\n for (let i = 0; i < a.length; i += 1) {\n if (!deepEqual(asAny(a[i], sourceCodeInfo), asAny(b[i], sourceCodeInfo), sourceCodeInfo))\n return false\n }\n return true\n }\n if (isRegularExpression(a) && isRegularExpression(b))\n return a.s === b.s && a.f === b.f\n\n if (isUnknownRecord(a) && isUnknownRecord(b)) {\n const aKeys = Object.keys(a)\n const bKeys = Object.keys(b)\n if (aKeys.length !== bKeys.length)\n return false\n\n for (let i = 0; i < aKeys.length; i += 1) {\n const key = asString(aKeys[i], sourceCodeInfo)\n if (!deepEqual(a[key], b[key], sourceCodeInfo))\n return false\n }\n return true\n }\n return false\n}\n\nexport function toNonNegativeInteger(num: number): number {\n return Math.max(0, Math.ceil(num))\n}\n\nexport function toAny(value: unknown): Any {\n return (value ?? null) as Any\n}\n\nfunction clone<T>(value: T): T {\n if (isObj(value)) {\n return Object.entries(value).reduce((result: Obj, entry) => {\n const [key, val] = entry\n result[key] = clone(val)\n return result\n }, {}) as T\n }\n if (Array.isArray(value))\n // eslint-disable-next-line ts/no-unsafe-return\n return value.map(item => clone(item)) as unknown as T\n\n return value\n}\n\nexport function cloneColl<T extends Coll>(value: T): T {\n return clone(value)\n}\n\nexport function joinSets<T>(...results: Set<T>[]): Set<T> {\n const result = new Set<T>()\n for (const symbols of results)\n symbols.forEach(symbol => result.add(symbol))\n\n return result\n}\n\nexport function addToSet<T>(target: Set<T>, source: Set<T>): void {\n source.forEach(symbol => target.add(symbol))\n}\n\nexport const EPSILON = 1e-10\n\nexport function approxEqual(a: number, b: number, epsilon: number = EPSILON): boolean {\n if (a === b) {\n return true\n }\n\n const diff = Math.abs(a - b)\n\n if (a === 0 || b === 0 || diff < epsilon) {\n // Use absolute error for values near zero\n return diff < epsilon\n }\n const absA = Math.abs(a)\n const absB = Math.abs(b)\n\n // Use relative error for larger values\n return diff / (absA + absB) < epsilon\n}\n\nexport function approxZero(value: number): boolean {\n return Math.abs(value) < EPSILON\n}\n\nexport function smartTrim(str: string, minIndent = 0): string {\n const lines = str.split('\\n')\n while (lines[0]?.match(/^\\s*$/)) {\n lines.shift() // Remove leading empty lines\n }\n while (lines[lines.length - 1]?.match(/^\\s*$/)) {\n lines.pop() // Remove trailing empty lines\n }\n const indent = lines.reduce((acc, line) => {\n if (line.match(/^\\s*$/))\n return acc // Skip empty lines\n const lineIndent = line.match(/^\\s*/)![0].length\n return Math.min(acc, lineIndent)\n }, Infinity)\n return lines.map(line => ' '.repeat(minIndent) + line.slice(indent)).join('\\n').trimEnd()\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 { Any, Arr, Obj, Seq } from '../../../interface'\nimport type { SourceCodeInfo } from '../../../tokenizer/token'\nimport { asArray, assertArray, assertCharArray } from '../../../typeGuards/array'\nimport { asAny, asSeq, assertAny, assertFunctionLike, assertSeq } from '../../../typeGuards/lits'\nimport { asNumber, assertNumber } from '../../../typeGuards/number'\nimport { assertString, assertStringOrNumber } from '../../../typeGuards/string'\nimport { collHasKey, compare, deepEqual, toNonNegativeInteger } from '../../../utils'\nimport { toFixedArity } from '../../../utils/arity'\nimport type { MaybePromise } from '../../../utils/maybePromise'\nimport { chain, filterSequential, findIndexSequential, mapSequential, reduceSequential } from '../../../utils/maybePromise'\nimport type { BuiltinNormalExpressions } from '../../interface'\nimport type { LitsModule } from '../interface'\n\nconst sequenceUtilsFunctions: BuiltinNormalExpressions = {\n 'position': {\n evaluate: ([seq, fn]: Arr, sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<number | null> => {\n assertFunctionLike(fn, sourceCodeInfo)\n if (seq === null)\n return null\n\n assertSeq(seq, sourceCodeInfo)\n const arr = typeof seq === 'string' ? seq.split('') : seq\n return chain(\n findIndexSequential(arr, elem => executeFunction(fn, [elem], contextStack, sourceCodeInfo)),\n index => index !== -1 ? index : null,\n )\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: ['number', 'null'] },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: ['sequence', 'null'] },\n fun: { type: 'function' },\n },\n variants: [{ argumentNames: ['seq', 'fun'] }],\n description: 'Returns the index of the first elements that passes the test implemented by $fun. If no element was found, `null` is returned.',\n seeAlso: ['index-of', 'some', 'find'],\n examples: [\n `\nlet su = import(\"sequence\");\nsu.position(\n [\"Albert\", \"Mojir\", 160, [1, 2]],\n string?\n)`,\n `\nlet su = import(\"sequence\");\nsu.position(\n [5, 10, 15, 20],\n -> $ > 10\n)`,\n `\nlet su = import(\"sequence\");\nsu.position(\n [5, 10, 15, 20],\n -> $ > 100\n)`,\n `\nlet su = import(\"sequence\");\nsu.position(\n null,\n -> $ > 100\n)`,\n ],\n },\n },\n 'last-index-of': {\n evaluate: ([seq, value], sourceCodeInfo): number | null => {\n assertAny(value, sourceCodeInfo)\n if (seq === null)\n return null\n\n assertSeq(seq, sourceCodeInfo)\n if (typeof seq === 'string') {\n assertString(value, sourceCodeInfo)\n const index = seq.lastIndexOf(value)\n return index !== -1 ? index : null\n }\n else {\n const index = seq.findLastIndex(item => deepEqual(asAny(item, sourceCodeInfo), value), sourceCodeInfo)\n return index !== -1 ? index : null\n }\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: ['number', 'null'] },\n args: {\n a: { type: 'sequence' },\n b: { type: 'any' },\n seq: { type: ['sequence', 'null'] },\n x: { type: 'any' },\n },\n variants: [{ argumentNames: ['seq', 'x'] }],\n description: 'Returns the last index of $x in $seq. If element is not present in $seq `null` is returned.',\n seeAlso: ['index-of'],\n examples: [\n 'let su = import(\"sequence\"); su.last-index-of([[1], [2], [1], [2]], [1])',\n 'let su = import(\"sequence\"); su.last-index-of([\"Albert\", \"Mojir\", 160, [1, 2]], \"Mojir\")',\n 'let su = import(\"sequence\"); su.last-index-of([5, 10, 15, 20, 15], 15)',\n 'let su = import(\"sequence\"); su.last-index-of([5, 10, 15, 20], 1)',\n 'let su = import(\"sequence\"); su.last-index-of(null, 1)',\n ],\n },\n },\n 'shift': {\n evaluate: ([seq], sourceCodeInfo): Any => {\n assertSeq(seq, sourceCodeInfo)\n if (typeof seq === 'string')\n return seq.substring(1)\n\n const copy = [...seq]\n copy.shift()\n return copy\n },\n arity: toFixedArity(1),\n docs: {\n category: 'sequence',\n returns: { type: ['sequence', 'null'] },\n args: { seq: { type: 'sequence' } },\n variants: [{ argumentNames: ['seq'] }],\n description: 'Returns a copy of $seq with first element removed. If $seq is empty `null` is returned.',\n seeAlso: ['sequence.unshift', 'pop', 'rest'],\n examples: [\n 'let su = import(\"sequence\"); su.shift([1, 2, 3])',\n 'let su = import(\"sequence\"); su.shift([])',\n ],\n },\n },\n 'splice': {\n evaluate: (params, sourceCodeInfo): Any => {\n const [seq, start, deleteCount, ...rest] = params\n assertSeq(seq, sourceCodeInfo)\n assertNumber(start, sourceCodeInfo, { integer: true })\n assertNumber(deleteCount, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const from = start < 0 ? seq.length + start : start\n\n if (Array.isArray(seq)) {\n return [...seq.slice(0, from), ...rest, ...seq.slice(from + deleteCount)]\n }\n\n rest.forEach(elem => assertString(elem, sourceCodeInfo))\n return `${seq.substring(0, from)}${rest.join('')}${seq.substring(from + deleteCount)}`\n },\n arity: { min: 3 },\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n seq: { type: 'sequence', rest: true },\n start: { type: 'integer' },\n deleteCount: { type: 'integer' },\n items: { type: 'any', rest: true },\n },\n variants: [\n { argumentNames: ['seq', 'start', 'deleteCount'] },\n { argumentNames: ['seq', 'start', 'deleteCount', 'items'] },\n ],\n description: 'Returns a a spliced array. Removes $deleteCount elements from $seq starting at $start and replaces them with $items. If $start is negative, it is counting from the end of the array.',\n seeAlso: ['slice', 'sequence.remove-at'],\n examples: [\n 'let su = import(\"sequence\"); su.splice([1, 2, 3, 4, 5], 2, 2, \"x\")',\n 'let su = import(\"sequence\"); su.splice([1, 2, 3, 4, 5], -2, 1, \"x\")',\n 'let su = import(\"sequence\"); su.splice(\"Albert\", 2, 2, \"fo\")',\n ],\n },\n },\n 'sort-by': {\n evaluate: (params: Arr, sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<Seq> => {\n const [seq, keyfn] = params\n const defaultComparer = params.length === 2\n\n assertSeq(seq, sourceCodeInfo)\n assertFunctionLike(keyfn, sourceCodeInfo)\n const comparer = defaultComparer ? null : params[2]\n\n const isString = typeof seq === 'string'\n const arr = isString ? seq.split('') : [...seq]\n\n // Pre-compute all keys using mapSequential (async-safe)\n return chain(\n mapSequential(arr, elem => executeFunction(keyfn, [elem], contextStack, sourceCodeInfo)),\n (keys) => {\n if (defaultComparer) {\n // Create indexed pairs, sort by pre-computed keys\n const indexed = arr.map((elem, i) => ({ elem, key: keys[i]! }))\n indexed.sort((a, b) => {\n assertStringOrNumber(a.key, sourceCodeInfo)\n assertStringOrNumber(b.key, sourceCodeInfo)\n return compare(a.key, b.key, sourceCodeInfo)\n })\n const sorted = indexed.map(x => x.elem)\n return isString ? (sorted as string[]).join('') : sorted\n }\n else {\n assertFunctionLike(comparer, sourceCodeInfo)\n // Pre-compute keys, then need pairwise comparisons — these may also be async\n // For sort-by with custom comparer, we must use a non-async sort since\n // Array.sort requires sync comparators\n const indexed = arr.map((elem, i) => ({ elem, key: keys[i]! }))\n indexed.sort((a, b) => {\n const compareValue = executeFunction(comparer, [a.key, b.key], contextStack, sourceCodeInfo)\n if (compareValue instanceof Promise) {\n throw new TypeError('Async functions cannot be used as sort-by comparators')\n }\n assertNumber(compareValue, sourceCodeInfo, { finite: true })\n return compareValue\n })\n const sorted = indexed.map(x => x.elem)\n return isString ? (sorted as string[]).join('') : sorted\n }\n },\n )\n },\n arity: { min: 2, max: 3 },\n docs: {\n category: 'sequence',\n returns: { type: 'any', rest: true },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: 'sequence' },\n keyfn: { type: 'function' },\n comparer: { type: 'function' },\n },\n variants: [\n { argumentNames: ['seq', 'keyfn'] },\n { argumentNames: ['seq', 'keyfn', 'comparer'] },\n ],\n description: 'Returns a sorted sequence of the items in $seq, where the sort order is determined by comparing `(keyfn item)`. If no $comparer is supplied, uses builtin `compare`.',\n seeAlso: ['sort', 'compare'],\n examples: [\n 'let su = import(\"sequence\"); su.sort-by([\"Albert\", \"Mojir\", \"Nina\"], count)',\n 'let su = import(\"sequence\"); su.sort-by([\"Albert\", \"Mojir\", \"Nina\"], count)',\n 'let su = import(\"sequence\"); su.sort-by(\"Albert\", lower-case, -> $2 compare $1)',\n ],\n },\n },\n 'take': {\n evaluate: ([input, n], sourceCodeInfo): Seq => {\n assertNumber(n, sourceCodeInfo)\n assertSeq(input, sourceCodeInfo)\n const num = Math.max(Math.ceil(n), 0)\n return input.slice(0, num)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'integer' },\n n: { type: 'integer' },\n seq: { type: 'sequence' },\n },\n variants: [{ argumentNames: ['seq', 'n'] }],\n description: 'Constructs a new array/string with the $n first elements from $seq.',\n seeAlso: ['sequence.take-last', 'sequence.take-while', 'sequence.drop', 'slice', 'sequence.split-at'],\n examples: [\n 'let su = import(\"sequence\"); su.take([1, 2, 3, 4, 5], 3)',\n 'let su = import(\"sequence\"); su.take([1, 2, 3, 4, 5], 3)',\n 'let su = import(\"sequence\"); su.take([1, 2, 3, 4, 5], 0)',\n 'let su = import(\"sequence\"); su.take(\"Albert\", 2)',\n 'let su = import(\"sequence\"); su.take(\"Albert\", 50)',\n ],\n },\n },\n 'take-last': {\n evaluate: ([array, n], sourceCodeInfo): Seq => {\n assertSeq(array, sourceCodeInfo)\n assertNumber(n, sourceCodeInfo)\n const num = Math.max(Math.ceil(n), 0)\n const from = array.length - num\n return array.slice(from)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'integer' },\n n: { type: 'integer' },\n seq: { type: 'sequence' },\n },\n variants: [{ argumentNames: ['n', 'seq'] }],\n description: 'Constructs a new array with the $n last elements from $seq.',\n seeAlso: ['sequence.take', 'sequence.drop-last'],\n examples: [\n 'let su = import(\"sequence\"); su.take-last([1, 2, 3, 4, 5], 3)',\n 'let su = import(\"sequence\"); su.take-last([1, 2, 3, 4, 5], 3)',\n 'let su = import(\"sequence\"); su.take-last([1, 2, 3, 4, 5], 0)',\n ],\n },\n },\n 'take-while': {\n evaluate: ([seq, fn]: Arr, sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<Any> => {\n assertSeq(seq, sourceCodeInfo)\n assertFunctionLike(fn, sourceCodeInfo)\n\n const arr = typeof seq === 'string' ? seq.split('') : Array.from(seq)\n // Find the first index where the predicate is false\n return chain(\n findIndexSequential(arr, elem => chain(\n executeFunction(fn, [elem], contextStack, sourceCodeInfo),\n result => !result,\n )),\n (index) => {\n const taken = index === -1 ? arr : arr.slice(0, index)\n return typeof seq === 'string' ? taken.join('') : taken\n },\n )\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: 'sequence' },\n fun: { type: 'function' },\n },\n variants: [{ argumentNames: ['seq', 'fun'] }],\n description: 'Returns the members of $seq in order, stopping before the first one for which `predicate` returns a falsy value.',\n seeAlso: ['sequence.take', 'sequence.drop-while', 'sequence.split-with'],\n examples: [\n `\nlet su = import(\"sequence\");\nsu.take-while(\n [1, 2, 3, 2, 1],\n -> $ < 3\n)`,\n `\nlet su = import(\"sequence\");\nsu.take-while(\n [1, 2, 3, 2, 1],\n -> $ > 3\n)`,\n ],\n },\n },\n 'drop': {\n evaluate: ([input, n], sourceCodeInfo): Seq => {\n assertNumber(n, sourceCodeInfo)\n const num = Math.max(Math.ceil(n), 0)\n assertSeq(input, sourceCodeInfo)\n return input.slice(num)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'integer' },\n seq: { type: 'sequence' },\n n: { type: 'integer' },\n },\n variants: [{ argumentNames: ['seq', 'n'] }],\n description: 'Constructs a new array/string with the $n first elements dropped from $seq.',\n seeAlso: ['sequence.drop-last', 'sequence.drop-while', 'sequence.take', 'slice', 'sequence.split-at'],\n examples: [\n 'let su = import(\"sequence\"); su.drop([1, 2, 3, 4, 5], 3)',\n 'let su = import(\"sequence\"); su.drop([1, 2, 3, 4, 5], 0)',\n 'let su = import(\"sequence\"); su.drop(\"Albert\", 2)',\n 'let su = import(\"sequence\"); su.drop(\"Albert\", 50)',\n ],\n },\n },\n 'drop-last': {\n evaluate: ([array, n], sourceCodeInfo): Seq => {\n assertSeq(array, sourceCodeInfo)\n assertNumber(n, sourceCodeInfo)\n const num = Math.max(Math.ceil(n), 0)\n\n const from = array.length - num\n return array.slice(0, from)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'integer' },\n seq: { type: 'sequence' },\n n: { type: 'integer' },\n },\n variants: [{ argumentNames: ['seq', 'n'] }],\n description: 'Constructs a new array with the $n last elements dropped from $seq.',\n seeAlso: ['sequence.drop', 'sequence.take-last'],\n examples: [\n 'let su = import(\"sequence\"); su.drop-last([1, 2, 3, 4, 5], 3)',\n 'let su = import(\"sequence\"); su.drop-last([1, 2, 3, 4, 5], 3)',\n 'let su = import(\"sequence\"); su.drop-last([1, 2, 3, 4, 5], 0)',\n ],\n },\n },\n 'drop-while': {\n evaluate: ([seq, fn]: Arr, sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<Any> => {\n assertSeq(seq, sourceCodeInfo)\n assertFunctionLike(fn, sourceCodeInfo)\n\n const arr = Array.isArray(seq) ? seq : seq.split('')\n return chain(\n findIndexSequential(arr, elem => chain(\n executeFunction(fn, [elem], contextStack, sourceCodeInfo),\n result => !result,\n )),\n (from) => {\n if (from === -1)\n return typeof seq === 'string' ? '' : []\n return typeof seq === 'string' ? arr.slice(from).join('') : seq.slice(from)\n },\n )\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: 'sequence' },\n fun: { type: 'function' },\n },\n variants: [{ argumentNames: ['seq', 'fun'] }],\n description: 'Returns the members of $seq in order, skipping the fist elements for witch the `predicate` returns a truethy value.',\n seeAlso: ['sequence.drop', 'sequence.take-while', 'sequence.split-with'],\n examples: [\n `\nlet su = import(\"sequence\");\nsu.drop-while(\n [1, 2, 3, 2, 1],\n -> $ < 3\n)`,\n `\nlet su = import(\"sequence\");\nsu.drop-while(\n [1, 2, 3, 2, 1],\n -> $ > 3\n)`,\n ],\n },\n },\n 'unshift': {\n evaluate: ([seq, ...values], sourceCodeInfo): Seq => {\n assertSeq(seq, sourceCodeInfo)\n if (typeof seq === 'string') {\n assertCharArray(values, sourceCodeInfo)\n return [...values, seq].join('')\n }\n const copy = [...seq]\n copy.unshift(...values)\n return copy\n },\n arity: { min: 2 },\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'any' },\n seq: { type: 'sequence' },\n values: { type: 'any', rest: true },\n },\n variants: [{ argumentNames: ['seq', 'values'] }],\n description: 'Returns copy of $seq with $values added to the beginning.',\n seeAlso: ['push', 'sequence.shift', '++'],\n examples: [\n 'let su = import(\"sequence\"); su.unshift([1, 2, 3], 4)',\n 'let su = import(\"sequence\"); su.unshift([1, 2, 3], 4)',\n 'let su = import(\"sequence\"); su.unshift([1, 2, 3], 4, 5, 6)',\n `\nlet su = import(\"sequence\");\nlet l = [1, 2, 3];\nsu.unshift(l, 4);\nl`,\n ],\n },\n },\n 'distinct': {\n evaluate: ([input], sourceCodeInfo): Seq => {\n assertSeq(input, sourceCodeInfo)\n\n if (Array.isArray(input)) {\n const result: Any[] = []\n for (const item of input) {\n assertAny(item, sourceCodeInfo)\n if (!result.some(existingItem => deepEqual(existingItem, item, sourceCodeInfo))) {\n result.push(item)\n }\n }\n return result\n }\n\n return Array.from(new Set(input.split(''))).join('')\n },\n arity: toFixedArity(1),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: { seq: { type: 'sequence' } },\n variants: [{ argumentNames: ['seq'] }],\n description: 'Returns a copy of $seq with no duplicates.',\n seeAlso: ['sequence.frequencies'],\n examples: [\n 'let su = import(\"sequence\"); su.distinct([[1], [2], [3], [1], [3], [5]])',\n 'let su = import(\"sequence\"); su.distinct([1, 2, 3, 1, 3, 5])',\n 'let su = import(\"sequence\"); su.distinct(\"Albert Mojir\")',\n 'let su = import(\"sequence\"); su.distinct([])',\n 'let su = import(\"sequence\"); su.distinct(\"\")',\n ],\n },\n },\n 'remove': {\n evaluate: ([input, fn], sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<Seq> => {\n assertFunctionLike(fn, sourceCodeInfo)\n assertSeq(input, sourceCodeInfo)\n const arr = Array.isArray(input) ? input : input.split('')\n return chain(\n filterSequential(arr, elem => chain(\n executeFunction(fn, [elem], contextStack, sourceCodeInfo),\n result => !result,\n )),\n filtered => typeof input === 'string' ? filtered.join('') : filtered,\n )\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: 'sequence' },\n fun: { type: 'function' },\n },\n variants: [{ argumentNames: ['seq', 'fun'] }],\n description: 'Returns a new sequence of items in $seq for witch `pred(item)` returns a falsy value.',\n seeAlso: ['filter', 'sequence.remove-at'],\n examples: [\n 'let su = import(\"sequence\"); su.remove([1, 2, 3, 1, 3, 5], odd?)',\n 'let su = import(\"sequence\"); su.remove([1, 2, 3, 1, 3, 5], even?)',\n 'let su = import(\"sequence\"); su.remove(\"Albert Mojir\", -> \"aoueiyAOUEIY\" contains? $)',\n ],\n },\n },\n 'remove-at': {\n evaluate: ([input, index], sourceCodeInfo): Seq => {\n assertNumber(index, sourceCodeInfo, { integer: true })\n assertSeq(input, sourceCodeInfo)\n\n const at = index < 0 ? input.length + index : index\n if (at < 0 || at >= input.length)\n return input\n\n if (Array.isArray(input)) {\n return input.filter((_, i) => i !== at)\n }\n return `${input.substring(0, at)}${input.substring(at + 1)}`\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'integer' },\n seq: { type: 'sequence' },\n n: { type: 'number' },\n },\n variants: [{ argumentNames: ['seq', 'n'] }],\n description: 'Returns a new sequence of all items in $seq except item at position $n. If $n is negative, it is counting from the end of the sequence.',\n seeAlso: ['sequence.remove', 'sequence.splice'],\n examples: [\n 'let su = import(\"sequence\"); su.remove-at([1, 2, 3, 1, 3, 5], 2)',\n 'let su = import(\"sequence\"); su.remove-at(\"Albert\", -2)',\n 'let su = import(\"sequence\"); su.remove-at([1, 2, 3, 1, 3, 5], 0)',\n 'let su = import(\"sequence\"); su.remove-at([1, 2, 3, 1, 3, 5], -1)',\n 'let su = import(\"sequence\"); su.remove-at(\"Albert Mojir\", 6)',\n ],\n },\n },\n 'split-at': {\n evaluate: ([seq, pos], sourceCodeInfo): Seq => {\n assertNumber(pos, sourceCodeInfo, { integer: true })\n assertSeq(seq, sourceCodeInfo)\n\n const at = pos < 0 ? seq.length + pos : pos\n return [seq.slice(0, at), seq.slice(at)]\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'integer' },\n seq: { type: 'sequence' },\n n: { type: 'number' },\n },\n variants: [{ argumentNames: ['seq', 'n'] }],\n description: 'Returns a pair of sequence `[take(pos input), drop(pos input)]`.',\n seeAlso: ['sequence.split-with', 'sequence.take', 'sequence.drop'],\n examples: [\n 'let su = import(\"sequence\"); su.split-at([1, 2, 3, 4, 5], 2)',\n 'let su = import(\"sequence\"); su.split-at(\"Albert\", -2)',\n 'let su = import(\"sequence\"); su.split-at([1, 2, 3, 4, 5], -2)',\n 'let su = import(\"sequence\"); su.split-at(\"Albert\", 2)',\n ],\n },\n },\n\n 'split-with': {\n evaluate: ([seq, fn], sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<Seq> => {\n assertFunctionLike(fn, sourceCodeInfo)\n assertSeq(seq, sourceCodeInfo)\n const seqIsArray = Array.isArray(seq)\n const arr = seqIsArray ? seq : seq.split('')\n return chain(\n findIndexSequential(arr, elem => chain(\n executeFunction(fn, [elem], contextStack, sourceCodeInfo),\n result => !result,\n )),\n (index) => {\n if (index === -1)\n return [seq, seqIsArray ? [] : '']\n return [seq.slice(0, index), seq.slice(index)]\n },\n )\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: 'sequence' },\n fun: { type: 'function' },\n },\n variants: [{ argumentNames: ['seq', 'fun'] }],\n description: 'Returns a pair of sequences `[take-while(input, fun), drop-while(input, fun)]`.',\n seeAlso: ['sequence.split-at', 'sequence.take-while', 'sequence.drop-while'],\n examples: [\n 'let su = import(\"sequence\"); su.split-with([1, 2, 3, 4, 5], odd?)',\n 'let su = import(\"sequence\"); su.split-with([1, 2, 3, 4, 5], -> $ > 3)',\n 'let su = import(\"sequence\"); su.split-with(\"Albert\", -> $ <= \"o\")',\n ],\n },\n },\n\n 'frequencies': {\n evaluate: ([seq], sourceCodeInfo): Obj => {\n assertSeq(seq, sourceCodeInfo)\n\n const arr = typeof seq === 'string' ? seq.split('') : seq\n\n return arr.reduce((result: Obj, val) => {\n assertString(val, sourceCodeInfo)\n if (collHasKey(result, val))\n result[val] = (result[val] as number) + 1\n else\n result[val] = 1\n\n return result\n }, {})\n },\n arity: toFixedArity(1),\n docs: {\n category: 'sequence',\n returns: { type: 'object' },\n args: { seq: { type: 'sequence' } },\n variants: [{ argumentNames: ['seq'] }],\n description: 'Returns an object from distinct items in $seq to the number of times they appear. Note that all items in $seq must be valid object keys i.e. strings.',\n seeAlso: ['sequence.group-by', 'sequence.distinct', 'vector.count-values'],\n examples: [\n 'let su = import(\"sequence\"); su.frequencies([\"Albert\", \"Mojir\", \"Nina\", \"Mojir\"])',\n 'let su = import(\"sequence\"); su.frequencies(\"Pneumonoultramicroscopicsilicovolcanoconiosis\")',\n ],\n },\n },\n\n 'group-by': {\n evaluate: ([seq, fn], sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<Obj> => {\n assertFunctionLike(fn, sourceCodeInfo)\n assertSeq(seq, sourceCodeInfo)\n const arr = Array.isArray(seq) ? seq : seq.split('')\n\n return reduceSequential(arr, (result: Obj, val) => {\n return chain(executeFunction(fn, [val], contextStack, sourceCodeInfo), (key) => {\n assertString(key, sourceCodeInfo)\n if (!collHasKey(result, key))\n result[key] = []\n\n ;(result[key] as Arr).push(val)\n return result\n })\n }, {})\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'object' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: 'sequence' },\n fun: { type: 'function' },\n },\n variants: [{ argumentNames: ['seq', 'fun'] }],\n description: 'Returns an object of the elements of $seq keyed by the result of $fun on each element. The value at each key will be an array of the corresponding elements.',\n seeAlso: ['sequence.frequencies', 'sequence.partition-by'],\n examples: [\n 'let su = import(\"sequence\"); su.group-by([{ name: \"Albert\" }, { name: \"Albert\" }, { name: \"Mojir\" }], \"name\")',\n 'let su = import(\"sequence\"); su.group-by([{name: \"Albert\"}, {name: \"Albert\"}, {name: \"Mojir\"}], \"name\")',\n 'let su = import(\"sequence\"); su.group-by(\"Albert Mojir\", -> \"aoueiAOUEI\" contains? $ ? \"vowel\" : \"other\")',\n ],\n },\n },\n\n 'partition': {\n evaluate: (params, sourceCodeInfo): Seq => {\n const seq = asSeq(params[0], sourceCodeInfo)\n const n = toNonNegativeInteger(asNumber(params[1], sourceCodeInfo))\n const step = params.length >= 3 ? toNonNegativeInteger(asNumber(params[2], sourceCodeInfo)) : n\n const pad = params.length === 4\n ? params[3] === null ? [] : asArray(params[3], sourceCodeInfo)\n : undefined\n\n return partitionHelper(n, step, seq, pad, sourceCodeInfo)\n },\n arity: { min: 2, max: 4 },\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'number' },\n seq: { type: 'sequence' },\n n: { type: 'number' },\n step: { type: 'number' },\n pad: { type: 'array' },\n },\n variants: [\n { argumentNames: ['seq', 'n'] },\n { argumentNames: ['seq', 'n', 'step'] },\n { argumentNames: ['seq', 'n', 'step', 'pad'] },\n ],\n description: 'Returns an array of sequences of $n items each, at offsets $step apart. If $step is not supplied, defaults to $n. If a $pad array is supplied, use its elements as necessary to complete last partition upto $n items. In case there are not enough padding elements, return a partition with less than $n items.',\n seeAlso: ['sequence.partition-all', 'sequence.partition-by'],\n examples: [\n 'let su = import(\"sequence\"); su.partition(range(20), 4)',\n 'let su = import(\"sequence\"); su.partition(range(20), 4)',\n 'let su = import(\"sequence\"); su.partition(range(22), 4)',\n 'let su = import(\"sequence\"); su.partition(range(20), 4, 6)',\n 'let su = import(\"sequence\"); su.partition(range(20), 4, 3)',\n 'let su = import(\"sequence\"); su.partition(range(20), 3, 6, [\"a\"])',\n 'let su = import(\"sequence\"); su.partition(range(20), 4, 6, [\"a\"])',\n 'let su = import(\"sequence\"); su.partition(range(20), 4, 6, [\"a\", \"b\", \"c\", \"d\"])',\n 'let su = import(\"sequence\"); su.partition([\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"], 3, 1)',\n 'let su = import(\"sequence\"); su.partition([1, 2, 3, 4], 10)',\n 'let su = import(\"sequence\"); su.partition([1, 2, 3, 4], 10, 10)',\n 'let su = import(\"sequence\"); su.partition([1, 2, 3, 4], 10, 10, [])',\n 'let su = import(\"sequence\"); su.partition([1, 2, 3, 4], 10, 10, null)',\n 'let su = import(\"sequence\"); su.partition(\"superfragilistic\", 5)',\n 'let su = import(\"sequence\"); su.partition(\"superfragilistic\", 5, 5, null)',\n 'let su = import(\"sequence\"); let foo = [5, 6, 7, 8]; su.partition(foo, 2, 1, foo)',\n ],\n },\n },\n\n 'partition-all': {\n evaluate: (params, sourceCodeInfo): Seq => {\n const seq = asSeq(params[0], sourceCodeInfo)\n const n = toNonNegativeInteger(asNumber(params[1], sourceCodeInfo))\n const step = params.length === 3 ? toNonNegativeInteger(asNumber(params[2], sourceCodeInfo)) : n\n\n return partitionHelper(n, step, seq, [], sourceCodeInfo)\n },\n arity: { min: 2, max: 3 },\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'number' },\n seq: { type: 'sequence' },\n n: { type: 'number' },\n step: { type: 'number' },\n },\n variants: [\n { argumentNames: ['seq', 'n'] },\n { argumentNames: ['seq', 'n', 'step'] },\n ],\n description: 'Returns an array of sequences like partition, but may include partitions with fewer than n items at the end.',\n seeAlso: ['sequence.partition', 'sequence.partition-by'],\n examples: [\n 'let su = import(\"sequence\"); su.partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)',\n 'let su = import(\"sequence\"); su.partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)',\n 'let su = import(\"sequence\"); su.partition([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)',\n 'let su = import(\"sequence\"); su.partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 2, 4)',\n ],\n },\n },\n\n 'partition-by': {\n evaluate: ([seq, fn], sourceCodeInfo, contextStack, { executeFunction }): MaybePromise<Seq> => {\n assertFunctionLike(fn, sourceCodeInfo)\n assertSeq(seq, sourceCodeInfo)\n const isStringSeq = typeof seq === 'string'\n const arr = isStringSeq ? seq.split('') : seq\n\n type Acc = { result: Arr, oldValue: unknown }\n return chain(\n reduceSequential(arr, (acc: Acc, elem) => {\n return chain(executeFunction(fn, [elem], contextStack, sourceCodeInfo), (value) => {\n if (value !== acc.oldValue) {\n acc.result.push([])\n acc.oldValue = value\n }\n ;(acc.result[acc.result.length - 1] as Arr).push(elem)\n return acc\n })\n }, { result: [], oldValue: undefined as unknown }),\n ({ result }) => isStringSeq ? result.map(elem => (elem as Arr).join('')) : result,\n )\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'function' },\n seq: { type: 'sequence' },\n fun: { type: 'function' },\n },\n variants: [{ argumentNames: ['seq', 'fun'] }],\n description: 'Applies $fun to each value in $seq, splitting it each time $fun returns a new value. Returns an array of sequences.',\n seeAlso: ['sequence.partition', 'sequence.partition-all', 'sequence.group-by'],\n examples: [\n 'let su = import(\"sequence\"); su.partition-by([1, 2, 3, 4, 5], odd?)',\n 'let su = import(\"sequence\"); su.partition-by([1, 2, 3, 4, 5], -> $ == 3)',\n 'let su = import(\"sequence\"); su.partition-by([1, 1, 1, 2, 2, 3, 3], odd?)',\n 'let su = import(\"sequence\"); su.partition-by(\"Leeeeeerrroyyy\", identity)',\n ],\n },\n },\n 'ends-with?': {\n evaluate: ([str, search], sourceCodeInfo): boolean => {\n assertSeq(str, sourceCodeInfo)\n\n if (typeof str === 'string') {\n assertString(search, sourceCodeInfo)\n return str.endsWith(search)\n }\n\n return deepEqual(asAny(str.at(-1), sourceCodeInfo), asAny(search, sourceCodeInfo), sourceCodeInfo)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'boolean' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'sequence' },\n seq: { type: 'sequence' },\n suffix: { type: 'sequence' },\n },\n variants: [{ argumentNames: ['seq', 'suffix'] }],\n description: 'Returns `true` if $seq ends with $suffix, otherwise `false`.',\n seeAlso: ['sequence.starts-with?'],\n examples: [\n 'let su = import(\"sequence\"); su.ends-with?([[1], [2], [3], [4], [5]], [5])',\n 'let su = import(\"sequence\"); su.ends-with?([[1], [2], [3], [4], [5]], 5)',\n 'let su = import(\"sequence\"); su.ends-with?([1, 2, 3, 4, 5], 5)',\n 'let su = import(\"sequence\"); su.ends-with?([1, 2, 3, 4, 5], [5])',\n 'let su = import(\"sequence\"); su.ends-with?(\"Albert\", \"rt\")',\n 'let su = import(\"sequence\"); su.ends-with?(\"Albert\", \"RT\")',\n ],\n },\n },\n 'starts-with?': {\n evaluate: ([seq, search], sourceCodeInfo): boolean => {\n assertSeq(seq, sourceCodeInfo)\n\n if (typeof seq === 'string') {\n assertString(search, sourceCodeInfo)\n return seq.startsWith(search)\n }\n\n return deepEqual(asAny(seq[0], sourceCodeInfo), asAny(search, sourceCodeInfo), sourceCodeInfo)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'boolean' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'sequence' },\n seq: { type: 'sequence' },\n prefix: { type: 'sequence' },\n },\n variants: [{ argumentNames: ['seq', 'prefix'] }],\n description: 'Returns `true` if $seq starts with $prefix, otherwise `false`.',\n seeAlso: ['sequence.ends-with?'],\n examples: [\n 'let su = import(\"sequence\"); su.starts-with?([[1], [2], [3], [4], [5]], [1])',\n 'let su = import(\"sequence\"); su.starts-with?([1, 2, 3, 4, 5], 1)',\n 'let su = import(\"sequence\"); su.starts-with?([1, 2, 3, 4, 5], [1])',\n 'let su = import(\"sequence\"); su.starts-with?(\"Albert\", \"Al\")',\n 'let su = import(\"sequence\"); su.starts-with?(\"Albert\", \"al\")',\n ],\n },\n },\n 'interleave': {\n evaluate: ([...seqs], sourceCodeInfo): Seq => {\n const isStringSeq = typeof seqs[0] === 'string'\n\n const seqsArr = isStringSeq\n ? seqs.map((seq) => {\n assertString(seq, sourceCodeInfo)\n return seq.split('')\n })\n : seqs.map((seq) => {\n assertArray(seq, sourceCodeInfo)\n return seq\n })\n\n const maxLength = Math.min(...seqsArr.map(seq => seq.length))\n const result: Arr = []\n for (let i = 0; i < maxLength; i += 1) {\n for (const seq of seqsArr) {\n if (i < seq.length)\n result.push(seq[i])\n }\n }\n return isStringSeq ? result.join('') : result\n },\n arity: { min: 1 },\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'sequence' },\n seqs: { type: 'sequence', rest: true },\n },\n variants: [{ argumentNames: ['seqs'] }],\n description: 'Returns a sequence of the first item from each of the $seqs, then the second item from each of the $seqs, until all items from the shortest seq are exhausted.',\n seeAlso: ['sequence.interpose', 'zipmap'],\n examples: [\n 'let su = import(\"sequence\"); su.interleave([1, 2, 3], [4, 5, 6])',\n 'let su = import(\"sequence\"); su.interleave(\"Albert\", \".,.,.,\")',\n 'let su = import(\"sequence\"); su.interleave([1, 2, 3], [4, 5, 6])',\n 'let su = import(\"sequence\"); su.interleave([1, 2, 3], [4, 5, 6], [7, 8, 9])',\n 'let su = import(\"sequence\"); su.interleave([1, 2, 3], [4, 5, 6], [7, 8])',\n 'let su = import(\"sequence\"); su.interleave([1, 2, 3], [4, 5, 6], [7])',\n 'let su = import(\"sequence\"); su.interleave([1, 2, 3], [4, 5, 6], [])',\n 'let su = import(\"sequence\"); su.interleave([1, 2, 3], [])',\n 'let su = import(\"sequence\"); su.interleave([])',\n ],\n },\n },\n 'interpose': {\n evaluate: ([seq, separator], sourceCodeInfo): Seq => {\n assertSeq(seq, sourceCodeInfo)\n if (typeof seq === 'string') {\n assertString(separator, sourceCodeInfo)\n return seq.split('').join(separator)\n }\n\n if (seq.length === 0)\n return []\n\n const result: Arr = []\n for (let i = 0; i < seq.length - 1; i += 1) {\n result.push(seq[i], separator)\n }\n result.push(seq[seq.length - 1])\n return result\n },\n arity: toFixedArity(2),\n docs: {\n category: 'sequence',\n returns: { type: 'sequence' },\n args: {\n a: { type: 'sequence' },\n b: { type: 'any' },\n seq: { type: 'sequence' },\n separator: { type: 'any' },\n },\n variants: [{ argumentNames: ['seq', 'separator'] }],\n description: 'Returns a sequence of the elements of $seq separated by $separator. If $seq is a string, the separator must be a string.',\n seeAlso: ['sequence.interleave', 'join'],\n examples: [\n 'let su = import(\"sequence\"); su.interpose(\"Albert\", \"-\")',\n 'let su = import(\"sequence\"); su.interpose([1, 2, 3, 4, 5], \"a\")',\n 'let su = import(\"sequence\"); su.interpose([\"Albert\", \"Mojir\", \"Nina\"], \", \")',\n 'let su = import(\"sequence\"); su.interpose(\"Albert\", \".\")',\n ],\n },\n },\n}\n\nfunction partitionHelper(n: number, step: number, seq: Seq, pad: Arr | undefined, sourceCodeInfo?: SourceCodeInfo) {\n assertNumber(step, sourceCodeInfo, { positive: true })\n const isStringSeq = typeof seq === 'string'\n\n const result: Arr[] = []\n let start = 0\n outer: while (start < seq.length) {\n const innerArr: Arr = []\n for (let i = start; i < start + n; i += 1) {\n if (i >= seq.length) {\n const padIndex = i - seq.length\n if (!pad) {\n start += step\n continue outer\n }\n if (padIndex >= pad.length)\n break\n\n innerArr.push(pad[padIndex])\n }\n else {\n innerArr.push(seq[i])\n }\n }\n result.push(innerArr)\n start += step\n }\n return isStringSeq ? result.map(x => x.join('')) : result\n}\n\nexport const sequenceUtilsModule: LitsModule = {\n name: 'sequence',\n functions: sequenceUtilsFunctions,\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","isLitsFunction","func","type","functionType","has","isNode","value","Array","isArray","valueToString","keys","find","key","RegExp","toString","JSON","stringify","getSourceCodeInfo","anyValue","getAssertionError","typeName","assertArray","assertCharArray","every","v","isCharArray","isUnknownRecord","asAny","assertAny","undefined","isAny","isSeq","asSeq","assertSeq","isColl","isRegularExpression","isObj","regexp","assertFunctionLike","isFunctionLike","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","asNumber","assertString","nonEmpty","char","isString","asString","assertStringOrNumber","isStringOrNumber","collHasKey","coll","getOwnPropertyDescriptor","deepEqual","a","b","epsilon","EPSILON","diff","abs","absA","absB","approxEqual","i","s","f","aKeys","bKeys","toNonNegativeInteger","num","ceil","toFixedArity","arity","min","chain","fn","Promise","then","async","chainRemainingMap","currentPromise","results","arr","startIndex","push","reduceSequential","initial","result","next","chainRemainingReduce","chainRemainingFilter","findIndexSequential","chainRemainingFindIndex","sequenceUtilsFunctions","evaluate","seq","contextStack","executeFunction","split","elem","index","docs","category","returns","args","fun","variants","argumentNames","description","seeAlso","examples","lastIndexOf","findLastIndex","item","shift","substring","copy","splice","params","start","deleteCount","rest","from","slice","forEach","items","keyfn","defaultComparer","comparer","mapSequential","indexed","map","sort","compare","sorted","compareValue","TypeError","take","input","n","array","taken","drop","unshift","distinct","some","existingItem","remove","filterSequential","filtered","at","_","pos","seqIsArray","frequencies","reduce","val","partition","step","pad","asArray","partitionHelper","isStringSeq","acc","oldValue","str","search","endsWith","suffix","startsWith","prefix","interleave","seqs","seqsArr","maxLength","interpose","separator","outer","innerArr","padIndex","sequenceUtilsModule","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,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ACD,OAAOI,EAAc3E,EAAO4C,IAAI5F,GAAKA,EAAEC,KAAK,KAAO+C,CACrD,CAEa,MAAA6F,EAAkC,CAC7C9N,KAAM,WACN+N,UAAWxF"}
|
|
@@ -5,6 +5,7 @@ import type { TokenStream } from '../tokenizer/tokenize';
|
|
|
5
5
|
import { AutoCompleter } from '../AutoCompleter/AutoCompleter';
|
|
6
6
|
import type { Arity } from '../builtin/interface';
|
|
7
7
|
import type { LitsModule } from '../builtin/modules/interface';
|
|
8
|
+
import type { MaybePromise } from '../utils/maybePromise';
|
|
8
9
|
import { Cache } from './Cache';
|
|
9
10
|
export interface LitsRuntimeInfo {
|
|
10
11
|
astCache: Cache | null;
|
|
@@ -42,15 +43,20 @@ export declare class Lits {
|
|
|
42
43
|
private modules;
|
|
43
44
|
constructor(config?: LitsConfig);
|
|
44
45
|
getRuntimeInfo(): LitsRuntimeInfo;
|
|
46
|
+
readonly async: {
|
|
47
|
+
run: (program: string, params?: ContextParams & FilePathParams) => Promise<unknown>;
|
|
48
|
+
context: (programOrAst: string | Ast, params?: ContextParams & FilePathParams) => Promise<Context>;
|
|
49
|
+
apply: (fn: LitsFunction, fnParams: unknown[], params?: ContextParams) => Promise<unknown>;
|
|
50
|
+
};
|
|
45
51
|
run(program: string, params?: ContextParams & FilePathParams): unknown;
|
|
46
52
|
context(programOrAst: string | Ast, params?: ContextParams & FilePathParams): Context;
|
|
47
53
|
getUndefinedSymbols(programOrAst: string | Ast, params?: ContextParams): Set<string>;
|
|
48
54
|
tokenize(program: string, tokenizeParams?: FilePathParams & MinifyParams): TokenStream;
|
|
49
55
|
parse(tokenStream: TokenStream): Ast;
|
|
50
|
-
evaluate(ast: Ast, params: ContextParams): Any
|
|
56
|
+
evaluate(ast: Ast, params: ContextParams): MaybePromise<Any>;
|
|
51
57
|
transformSymbols(tokenStream: TokenStream, transformer: (symbol: string) => string): TokenStream;
|
|
52
58
|
untokenize(tokenStream: TokenStream): string;
|
|
53
|
-
apply(fn: LitsFunction, fnParams: unknown[], params?: ContextParams): Any
|
|
59
|
+
apply(fn: LitsFunction, fnParams: unknown[], params?: ContextParams): MaybePromise<Any>;
|
|
54
60
|
private generateApplyFunctionCall;
|
|
55
61
|
private generateAst;
|
|
56
62
|
getAutoCompleter(program: string, position: number, params?: ContextParams): AutoCompleter;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Any } from '../interface';
|
|
2
2
|
import { type AstNode, type BindingTarget } from '../parser/types';
|
|
3
|
+
import type { MaybePromise } from '../utils/maybePromise';
|
|
3
4
|
export declare function walkDefaults(bindingTarget: BindingTarget, onDefault: (Node: AstNode) => void): void;
|
|
4
|
-
export declare function evaluateBindingNodeValues(target: BindingTarget, value: Any, evaluate: (Node: AstNode) => Any): Record<string, Any
|
|
5
|
+
export declare function evaluateBindingNodeValues(target: BindingTarget, value: Any, evaluate: (Node: AstNode) => MaybePromise<Any>): MaybePromise<Record<string, Any>>;
|
|
5
6
|
export declare function getAllBindingTargetNames(bindingTarget: BindingTarget): Record<string, true>;
|
|
@@ -4,6 +4,7 @@ import type { GetUndefinedSymbols, UndefinedSymbols } from '../getUndefinedSymbo
|
|
|
4
4
|
import type { Any, Arr } from '../interface';
|
|
5
5
|
import type { SpecialExpressionNode } from '../parser/types';
|
|
6
6
|
import type { SourceCodeInfo } from '../tokenizer/token';
|
|
7
|
+
import type { MaybePromise } from '../utils/maybePromise';
|
|
7
8
|
import type { SpecialExpressions } from '.';
|
|
8
9
|
export type Arity = {
|
|
9
10
|
min?: number;
|
|
@@ -76,7 +77,7 @@ export type SpecialExpressionDocs = FunctionDocs | CustomDocs;
|
|
|
76
77
|
export declare function isFunctionDocs(docs: SpecialExpressionDocs): docs is FunctionDocs;
|
|
77
78
|
type NormalExpressionEvaluator<T> = (params: Arr, sourceCodeInfo: SourceCodeInfo | undefined, contextStack: ContextStack, { executeFunction }: {
|
|
78
79
|
executeFunction: ExecuteFunction;
|
|
79
|
-
}) => T
|
|
80
|
+
}) => MaybePromise<T>;
|
|
80
81
|
export interface BuiltinNormalExpression<T> {
|
|
81
82
|
evaluate: NormalExpressionEvaluator<T>;
|
|
82
83
|
name?: string;
|
|
@@ -91,7 +92,7 @@ interface EvaluateHelpers {
|
|
|
91
92
|
getUndefinedSymbols: GetUndefinedSymbols;
|
|
92
93
|
}
|
|
93
94
|
export interface BuiltinSpecialExpression<T, N extends SpecialExpressionNode> {
|
|
94
|
-
evaluate: (node: N, contextStack: ContextStack, helpers: EvaluateHelpers) => T
|
|
95
|
+
evaluate: (node: N, contextStack: ContextStack, helpers: EvaluateHelpers) => MaybePromise<T>;
|
|
95
96
|
evaluateAsNormalExpression?: NormalExpressionEvaluator<T>;
|
|
96
97
|
arity: Arity;
|
|
97
98
|
docs?: SpecialExpressionDocs;
|