@mojir/lits 2.2.2 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/dist/cli/cli.js +1145 -1105
  2. package/dist/cli/src/AutoCompleter/AutoCompleter.d.ts +2 -1
  3. package/dist/cli/src/builtin/bindingNode.d.ts +3 -3
  4. package/dist/cli/src/builtin/index.d.ts +0 -1
  5. package/dist/cli/src/builtin/interface.d.ts +3 -4
  6. package/dist/cli/src/builtin/specialExpressionTypes.d.ts +0 -1
  7. package/dist/cli/src/builtin/specialExpressions/and.d.ts +2 -2
  8. package/dist/cli/src/builtin/specialExpressions/array.d.ts +2 -2
  9. package/dist/cli/src/builtin/specialExpressions/block.d.ts +2 -2
  10. package/dist/cli/src/builtin/specialExpressions/cond.d.ts +2 -2
  11. package/dist/cli/src/builtin/specialExpressions/if.d.ts +2 -2
  12. package/dist/cli/src/builtin/specialExpressions/loop.d.ts +2 -2
  13. package/dist/cli/src/builtin/specialExpressions/loops.d.ts +4 -4
  14. package/dist/cli/src/builtin/specialExpressions/object.d.ts +2 -2
  15. package/dist/cli/src/builtin/specialExpressions/or.d.ts +2 -2
  16. package/dist/cli/src/builtin/specialExpressions/qq.d.ts +2 -2
  17. package/dist/cli/src/builtin/specialExpressions/recur.d.ts +2 -2
  18. package/dist/cli/src/builtin/specialExpressions/switch.d.ts +2 -2
  19. package/dist/cli/src/builtin/specialExpressions/throw.d.ts +2 -2
  20. package/dist/cli/src/builtin/specialExpressions/try.d.ts +2 -2
  21. package/dist/cli/src/builtin/specialExpressions/unless.d.ts +2 -2
  22. package/dist/cli/src/builtin/utils.d.ts +2 -2
  23. package/dist/cli/src/evaluator/index.d.ts +2 -2
  24. package/dist/cli/src/evaluator/interface.d.ts +4 -3
  25. package/dist/cli/src/getUndefinedSymbols/index.d.ts +2 -2
  26. package/dist/cli/src/parser/ParserContext.d.ts +20 -0
  27. package/dist/cli/src/parser/helpers.d.ts +19 -0
  28. package/dist/cli/src/parser/index.d.ts +3 -0
  29. package/dist/cli/src/parser/subParsers/getPrecedence.d.ts +3 -0
  30. package/dist/cli/src/parser/subParsers/parseArray.d.ts +3 -0
  31. package/dist/cli/src/parser/subParsers/parseBindingTarget.d.ts +6 -0
  32. package/dist/cli/src/parser/subParsers/parseCond.d.ts +4 -0
  33. package/dist/cli/src/parser/subParsers/parseDo.d.ts +3 -0
  34. package/dist/cli/src/parser/subParsers/parseForOrDoseq.d.ts +4 -0
  35. package/dist/cli/src/parser/subParsers/parseFunction.d.ts +4 -0
  36. package/dist/cli/src/parser/subParsers/parseFunctionCall.d.ts +3 -0
  37. package/dist/cli/src/parser/subParsers/parseIfOrUnless.d.ts +5 -0
  38. package/dist/cli/src/parser/subParsers/parseImplicitBlock.d.ts +5 -0
  39. package/dist/cli/src/parser/subParsers/parseLet.d.ts +4 -0
  40. package/dist/cli/src/parser/subParsers/parseLoop.d.ts +4 -0
  41. package/dist/cli/src/parser/subParsers/parseNumber.d.ts +3 -0
  42. package/dist/cli/src/parser/subParsers/parseObject.d.ts +3 -0
  43. package/dist/cli/src/parser/subParsers/parseOperand.d.ts +3 -0
  44. package/dist/cli/src/parser/subParsers/parseRegexpShorthand.d.ts +3 -0
  45. package/dist/cli/src/parser/subParsers/parseReservedSymbol.d.ts +3 -0
  46. package/dist/cli/src/parser/subParsers/parseString.d.ts +4 -0
  47. package/dist/cli/src/parser/subParsers/parseSwitch.d.ts +4 -0
  48. package/dist/cli/src/parser/subParsers/parseSymbol.d.ts +3 -0
  49. package/dist/cli/src/parser/subParsers/parseTry.d.ts +4 -0
  50. package/dist/cli/src/parser/types.d.ts +19 -26
  51. package/dist/cli/src/testFramework/index.d.ts +3 -2
  52. package/dist/cli/src/tokenizer/token.d.ts +0 -2
  53. package/dist/cli/src/tokenizer/tokenizers.d.ts +2 -2
  54. package/dist/cli/src/typeGuards/astNode.d.ts +18 -19
  55. package/dist/cli/src/typeGuards/index.d.ts +0 -1
  56. package/dist/cli/src/typeGuards/lits.d.ts +0 -1
  57. package/dist/full.esm.js +1 -1
  58. package/dist/full.esm.js.map +1 -1
  59. package/dist/full.js +1 -1
  60. package/dist/full.js.map +1 -1
  61. package/dist/index.esm.js +1 -1
  62. package/dist/index.esm.js.map +1 -1
  63. package/dist/index.js +1 -1
  64. package/dist/index.js.map +1 -1
  65. package/dist/lits.iife.js +1 -1
  66. package/dist/lits.iife.js.map +1 -1
  67. package/dist/modules/assert.esm.js.map +1 -1
  68. package/dist/modules/assert.js.map +1 -1
  69. package/dist/modules/bitwise.esm.js.map +1 -1
  70. package/dist/modules/bitwise.js.map +1 -1
  71. package/dist/modules/collection.esm.js.map +1 -1
  72. package/dist/modules/collection.js.map +1 -1
  73. package/dist/modules/functional.esm.js.map +1 -1
  74. package/dist/modules/functional.js.map +1 -1
  75. package/dist/modules/grid.esm.js.map +1 -1
  76. package/dist/modules/grid.js.map +1 -1
  77. package/dist/modules/linear-algebra.esm.js.map +1 -1
  78. package/dist/modules/linear-algebra.js.map +1 -1
  79. package/dist/modules/matrix.esm.js.map +1 -1
  80. package/dist/modules/matrix.js.map +1 -1
  81. package/dist/modules/number-theory.esm.js.map +1 -1
  82. package/dist/modules/number-theory.js.map +1 -1
  83. package/dist/modules/random.esm.js.map +1 -1
  84. package/dist/modules/random.js.map +1 -1
  85. package/dist/modules/sequence.esm.js.map +1 -1
  86. package/dist/modules/sequence.js.map +1 -1
  87. package/dist/modules/src/AutoCompleter/AutoCompleter.d.ts +2 -1
  88. package/dist/modules/src/builtin/bindingNode.d.ts +3 -3
  89. package/dist/modules/src/builtin/index.d.ts +0 -1
  90. package/dist/modules/src/builtin/interface.d.ts +3 -4
  91. package/dist/modules/src/builtin/specialExpressionTypes.d.ts +0 -1
  92. package/dist/modules/src/builtin/specialExpressions/and.d.ts +2 -2
  93. package/dist/modules/src/builtin/specialExpressions/array.d.ts +2 -2
  94. package/dist/modules/src/builtin/specialExpressions/block.d.ts +2 -2
  95. package/dist/modules/src/builtin/specialExpressions/cond.d.ts +2 -2
  96. package/dist/modules/src/builtin/specialExpressions/if.d.ts +2 -2
  97. package/dist/modules/src/builtin/specialExpressions/loop.d.ts +2 -2
  98. package/dist/modules/src/builtin/specialExpressions/loops.d.ts +4 -4
  99. package/dist/modules/src/builtin/specialExpressions/object.d.ts +2 -2
  100. package/dist/modules/src/builtin/specialExpressions/or.d.ts +2 -2
  101. package/dist/modules/src/builtin/specialExpressions/qq.d.ts +2 -2
  102. package/dist/modules/src/builtin/specialExpressions/recur.d.ts +2 -2
  103. package/dist/modules/src/builtin/specialExpressions/switch.d.ts +2 -2
  104. package/dist/modules/src/builtin/specialExpressions/throw.d.ts +2 -2
  105. package/dist/modules/src/builtin/specialExpressions/try.d.ts +2 -2
  106. package/dist/modules/src/builtin/specialExpressions/unless.d.ts +2 -2
  107. package/dist/modules/src/builtin/utils.d.ts +2 -2
  108. package/dist/modules/src/evaluator/index.d.ts +2 -2
  109. package/dist/modules/src/evaluator/interface.d.ts +4 -3
  110. package/dist/modules/src/getUndefinedSymbols/index.d.ts +2 -2
  111. package/dist/modules/src/parser/ParserContext.d.ts +20 -0
  112. package/dist/modules/src/parser/helpers.d.ts +19 -0
  113. package/dist/modules/src/parser/index.d.ts +3 -0
  114. package/dist/modules/src/parser/subParsers/getPrecedence.d.ts +3 -0
  115. package/dist/modules/src/parser/subParsers/parseArray.d.ts +3 -0
  116. package/dist/modules/src/parser/subParsers/parseBindingTarget.d.ts +6 -0
  117. package/dist/modules/src/parser/subParsers/parseCond.d.ts +4 -0
  118. package/dist/modules/src/parser/subParsers/parseDo.d.ts +3 -0
  119. package/dist/modules/src/parser/subParsers/parseForOrDoseq.d.ts +4 -0
  120. package/dist/modules/src/parser/subParsers/parseFunction.d.ts +4 -0
  121. package/dist/modules/src/parser/subParsers/parseFunctionCall.d.ts +3 -0
  122. package/dist/modules/src/parser/subParsers/parseIfOrUnless.d.ts +5 -0
  123. package/dist/modules/src/parser/subParsers/parseImplicitBlock.d.ts +5 -0
  124. package/dist/modules/src/parser/subParsers/parseLet.d.ts +4 -0
  125. package/dist/modules/src/parser/subParsers/parseLoop.d.ts +4 -0
  126. package/dist/modules/src/parser/subParsers/parseNumber.d.ts +3 -0
  127. package/dist/modules/src/parser/subParsers/parseObject.d.ts +3 -0
  128. package/dist/modules/src/parser/subParsers/parseOperand.d.ts +3 -0
  129. package/dist/modules/src/parser/subParsers/parseRegexpShorthand.d.ts +3 -0
  130. package/dist/modules/src/parser/subParsers/parseReservedSymbol.d.ts +3 -0
  131. package/dist/modules/src/parser/subParsers/parseString.d.ts +4 -0
  132. package/dist/modules/src/parser/subParsers/parseSwitch.d.ts +4 -0
  133. package/dist/modules/src/parser/subParsers/parseSymbol.d.ts +3 -0
  134. package/dist/modules/src/parser/subParsers/parseTry.d.ts +4 -0
  135. package/dist/modules/src/parser/types.d.ts +19 -26
  136. package/dist/modules/src/testFramework/index.d.ts +3 -2
  137. package/dist/modules/src/tokenizer/token.d.ts +0 -2
  138. package/dist/modules/src/tokenizer/tokenizers.d.ts +2 -2
  139. package/dist/modules/src/typeGuards/astNode.d.ts +18 -19
  140. package/dist/modules/src/typeGuards/index.d.ts +0 -1
  141. package/dist/modules/src/typeGuards/lits.d.ts +0 -1
  142. package/dist/modules/string.esm.js.map +1 -1
  143. package/dist/modules/string.js.map +1 -1
  144. package/dist/modules/vector.esm.js.map +1 -1
  145. package/dist/modules/vector.js.map +1 -1
  146. package/dist/src/AutoCompleter/AutoCompleter.d.ts +2 -1
  147. package/dist/src/builtin/bindingNode.d.ts +3 -3
  148. package/dist/src/builtin/index.d.ts +0 -1
  149. package/dist/src/builtin/interface.d.ts +3 -4
  150. package/dist/src/builtin/specialExpressionTypes.d.ts +0 -1
  151. package/dist/src/builtin/specialExpressions/and.d.ts +2 -2
  152. package/dist/src/builtin/specialExpressions/array.d.ts +2 -2
  153. package/dist/src/builtin/specialExpressions/block.d.ts +2 -2
  154. package/dist/src/builtin/specialExpressions/cond.d.ts +2 -2
  155. package/dist/src/builtin/specialExpressions/if.d.ts +2 -2
  156. package/dist/src/builtin/specialExpressions/loop.d.ts +2 -2
  157. package/dist/src/builtin/specialExpressions/loops.d.ts +4 -4
  158. package/dist/src/builtin/specialExpressions/object.d.ts +2 -2
  159. package/dist/src/builtin/specialExpressions/or.d.ts +2 -2
  160. package/dist/src/builtin/specialExpressions/qq.d.ts +2 -2
  161. package/dist/src/builtin/specialExpressions/recur.d.ts +2 -2
  162. package/dist/src/builtin/specialExpressions/switch.d.ts +2 -2
  163. package/dist/src/builtin/specialExpressions/throw.d.ts +2 -2
  164. package/dist/src/builtin/specialExpressions/try.d.ts +2 -2
  165. package/dist/src/builtin/specialExpressions/unless.d.ts +2 -2
  166. package/dist/src/builtin/utils.d.ts +2 -2
  167. package/dist/src/evaluator/index.d.ts +2 -2
  168. package/dist/src/evaluator/interface.d.ts +4 -3
  169. package/dist/src/getUndefinedSymbols/index.d.ts +2 -2
  170. package/dist/src/parser/ParserContext.d.ts +20 -0
  171. package/dist/src/parser/helpers.d.ts +19 -0
  172. package/dist/src/parser/index.d.ts +3 -0
  173. package/dist/src/parser/subParsers/getPrecedence.d.ts +3 -0
  174. package/dist/src/parser/subParsers/parseArray.d.ts +3 -0
  175. package/dist/src/parser/subParsers/parseBindingTarget.d.ts +6 -0
  176. package/dist/src/parser/subParsers/parseCond.d.ts +4 -0
  177. package/dist/src/parser/subParsers/parseDo.d.ts +3 -0
  178. package/dist/src/parser/subParsers/parseForOrDoseq.d.ts +4 -0
  179. package/dist/src/parser/subParsers/parseFunction.d.ts +4 -0
  180. package/dist/src/parser/subParsers/parseFunctionCall.d.ts +3 -0
  181. package/dist/src/parser/subParsers/parseIfOrUnless.d.ts +5 -0
  182. package/dist/src/parser/subParsers/parseImplicitBlock.d.ts +5 -0
  183. package/dist/src/parser/subParsers/parseLet.d.ts +4 -0
  184. package/dist/src/parser/subParsers/parseLoop.d.ts +4 -0
  185. package/dist/src/parser/subParsers/parseNumber.d.ts +3 -0
  186. package/dist/src/parser/subParsers/parseObject.d.ts +3 -0
  187. package/dist/src/parser/subParsers/parseOperand.d.ts +3 -0
  188. package/dist/src/parser/subParsers/parseRegexpShorthand.d.ts +3 -0
  189. package/dist/src/parser/subParsers/parseReservedSymbol.d.ts +3 -0
  190. package/dist/src/parser/subParsers/parseString.d.ts +4 -0
  191. package/dist/src/parser/subParsers/parseSwitch.d.ts +4 -0
  192. package/dist/src/parser/subParsers/parseSymbol.d.ts +3 -0
  193. package/dist/src/parser/subParsers/parseTry.d.ts +4 -0
  194. package/dist/src/parser/types.d.ts +19 -26
  195. package/dist/src/testFramework/index.d.ts +3 -2
  196. package/dist/src/tokenizer/token.d.ts +0 -2
  197. package/dist/src/tokenizer/tokenizers.d.ts +2 -2
  198. package/dist/src/typeGuards/astNode.d.ts +18 -19
  199. package/dist/src/typeGuards/index.d.ts +0 -1
  200. package/dist/src/typeGuards/lits.d.ts +0 -1
  201. package/dist/testFramework.esm.js +1 -1
  202. package/dist/testFramework.esm.js.map +1 -1
  203. package/dist/testFramework.js +1 -1
  204. package/dist/testFramework.js.map +1 -1
  205. package/package.json +1 -1
  206. package/dist/cli/src/parser/Parser.d.ts +0 -58
  207. package/dist/modules/src/parser/Parser.d.ts +0 -58
  208. package/dist/src/parser/Parser.d.ts +0 -58
@@ -1 +1 @@
1
- {"version":3,"file":"functional.esm.js","sources":["../../src/utils/debug/getCodeMarker.ts","../../src/errors.ts","../../src/constants/constants.ts","../../src/utils/symbols.ts","../../src/utils/debug/debugTools.ts","../../src/typeGuards/litsFunction.ts","../../src/typeGuards/lits.ts","../../src/utils/getAssertionError.ts","../../src/utils/debug/getSourceCodeInfo.ts","../../src/utils/arity.ts","../../src/builtin/modules/functional/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 { LitsFunction, Node } 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 Node {\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 { 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\nexport function 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 './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'\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 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 { Arr } from '../../../interface'\nimport type {\n ComplementFunction,\n EveryPredFunction,\n FNullFunction,\n FunctionLike,\n JuxtFunction,\n SomePredFunction,\n} from '../../../parser/types'\nimport { getArityFromFunction, getCommonArityFromFunctions, toFixedArity } from '../../../utils/arity'\nimport { FUNCTION_SYMBOL } from '../../../utils/symbols'\nimport type { BuiltinNormalExpressions } from '../../interface'\nimport { asFunctionLike, assertFunctionLike } from '../../../typeGuards/lits'\nimport { LitsError } from '../../../errors'\nimport type { LitsModule } from '../interface'\n\nconst functionalUtilsNormalExpression: BuiltinNormalExpressions = {\n 'juxt': {\n evaluate: (params, sourceCodeInfo): JuxtFunction => {\n params.forEach(param => assertFunctionLike(param, sourceCodeInfo))\n const arity = getCommonArityFromFunctions(params as FunctionLike[])\n if (arity === null) {\n throw new LitsError('All functions must accept the same number of arguments', sourceCodeInfo)\n }\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'Juxt',\n params,\n arity,\n }\n },\n arity: { min: 1 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n a: { type: 'function' },\n b: { type: 'function' },\n fun: { type: 'function' },\n fns: { type: 'function', rest: true },\n },\n variants: [\n { argumentNames: ['fun'] },\n { argumentNames: ['fun', 'fns'] },\n ],\n description: `Takes one or many function and returns a function that is the juxtaposition of those functions.\nThe returned function takes a variable number of args,\nand returns a vector containing the result of applying each function to the args (left-to-right).`,\n seeAlso: ['comp'],\n examples: [\n `let { juxt } = import(\"functional\");\njuxt(+, *, min, max)(\n 3,\n 4,\n 6,\n)`,\n `let { juxt } = import(\"functional\");\njuxt(\"a\", \"b\")(\n {\n a: 1,\n b: 2,\n c: 3,\n d: 4\n }\n)`,\n `let { juxt } = import(\"functional\");\njuxt(+, *, min, max) apply range(1, 11)`,\n ],\n },\n },\n\n 'complement': {\n evaluate: ([fn], sourceCodeInfo): ComplementFunction => {\n const fun = asFunctionLike(fn, sourceCodeInfo)\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'Complement',\n function: fun,\n arity: getArityFromFunction(fun),\n }\n },\n arity: toFixedArity(1),\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: { fun: { type: 'function' } },\n variants: [{ argumentNames: ['fun'] }],\n description: 'Takes a function $fun and returns a new function that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value.',\n seeAlso: ['comp', 'functional.every-pred', 'functional.some-pred'],\n examples: [\n 'let { complement } = import(\"functional\");\\ncomplement(>)(1, 3)',\n 'let { complement } = import(\"functional\");\\ncomplement(<)(1, 3)',\n 'let { complement } = import(\"functional\");\\ncomplement(+)(1, 3)',\n 'let { complement } = import(\"functional\");\\ncomplement(+)(0, 0)',\n ],\n },\n },\n\n 'every-pred': {\n evaluate: (params, sourceCodeInfo): EveryPredFunction => {\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'EveryPred',\n params,\n arity: { min: 1, max: 1 },\n }\n },\n arity: { min: 1 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n fun: { type: 'function' },\n fns: { type: 'function', rest: true },\n },\n variants: [\n { argumentNames: ['fun'] },\n { argumentNames: ['fun', 'fns'] },\n ],\n description: `\nTakes a number of predicates and returns a function that returns \\`true\\` if all predicates\nreturn a truthy value against all of its arguments, else it returns \\`false\\`.`,\n seeAlso: ['functional.some-pred', 'functional.complement', 'collection.every?'],\n examples: [\n `let { every-pred } = import(\"functional\");\nevery-pred(string?, -> count($) > 3)(\n \"Albert\",\n \"Mojir\"\n)`,\n `let { every-pred } = import(\"functional\");\n(string? every-pred -> count($) > 3)(\n \"Albert\",\n \"M\"\n)`,\n ],\n hideOperatorForm: true,\n },\n },\n\n 'some-pred': {\n evaluate: (params, sourceCodeInfo): SomePredFunction => {\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'SomePred',\n params,\n arity: { min: 1, max: 1 },\n }\n },\n arity: { min: 1 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n fun: { type: 'function' },\n fns: { type: 'function', rest: true },\n },\n variants: [\n { argumentNames: ['fun'] },\n { argumentNames: ['fun', 'fns'] },\n ],\n description: 'Takes a number of `predicates` and returns a function that returns `true` if at least one of the `predicates` return a truthy `true` value against at least one of its arguments, else it returns `false`.',\n seeAlso: ['functional.every-pred', 'functional.complement', 'collection.any?'],\n examples: [\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)(\"Albert\", \"Mojir\")',\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)(\"a\", \"M\")',\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)(\"a\", [1, 2, 3])',\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)([1, 2, 3], [2])',\n ],\n hideOperatorForm: true,\n },\n },\n\n 'fnull': {\n evaluate: ([fn, ...params]: Arr, sourceCodeInfo): FNullFunction => {\n const fun = asFunctionLike(fn, sourceCodeInfo)\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'Fnull',\n function: fun,\n params,\n arity: getArityFromFunction(fun),\n }\n },\n arity: { min: 2 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n a: { type: 'function' },\n b: { type: 'any' },\n fun: { type: 'function' },\n arg: { type: 'any' },\n args: { type: 'any', rest: true },\n },\n variants: [\n { argumentNames: ['fun', 'arg'] },\n { argumentNames: ['fun', 'arg', 'args'] },\n ],\n description: 'Takes a function $fun, and returns a function that calls $fun, replacing a null argument to the corresponding argument.',\n seeAlso: ['identity', 'constantly'],\n examples: [\n 'let { fnull } = import(\"functional\");\\nfnull(inc, 0)(1)',\n 'let { fnull } = import(\"functional\");\\nfnull(inc, 0)(null)',\n 'let { fnull } = import(\"functional\");\\n(inc fnull 0)(null)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(null, 0)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(0, null)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(null, null)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(null, null, 3, 4)',\n ],\n },\n },\n}\n\nexport const functionalUtilsModule: LitsModule = {\n name: 'functional',\n functions: functionalUtilsNormalExpression,\n}\n"],"names":["getCodeMarker","sourceCodeInfo","position","code","leftPadding","column","rightPadding","length","repeat","Math","max","LitsError","Error","shortMessage","constructor","err","message","super","location","line","filePath","getLitsErrorMessage","this","Object","setPrototypeOf","prototype","name","NodeTypes","Number","String","NormalExpression","SpecialExpression","UserDefinedSymbol","NormalBuiltinSymbol","SpecialBuiltinSymbol","ReservedSymbol","Binding","Spread","NodeTypesSet","Set","values","functionTypeSet","FUNCTION_SYMBOL","REGEXP_SYMBOL","isLitsFunction","func","type","functionType","has","isNode","value","Array","isArray","valueToString","keys","find","key","RegExp","toString","JSON","stringify","isObj","regexp","isColl","isSeq","asFunctionLike","assertFunctionLike","isFunctionLike","typeName","anyValue","getSourceCodeInfo","getAssertionError","getArityFromFunction","param","toFixedArity","arity","min","functionalUtilsModule","functions","juxt","evaluate","params","forEach","reduce","acc","aMin","aMax","bMin","bMax","undefined","getCommonArityFromFunctions","docs","category","returns","args","a","b","fun","fns","rest","variants","argumentNames","description","seeAlso","examples","complement","fn","function","hideOperatorForm","fnull","arg"],"mappings":"AAEM,SAAUA,EAAcC,GAC5B,IAAKA,EAAeC,WAAaD,EAAeE,KAC9C,MAAO,GAET,MAAMC,EAAcH,EAAeC,SAASG,OAAS,EAC/CC,EAAeL,EAAeE,KAAKI,OAASH,EAAc,EAChE,MAAO,GAAG,IAAII,OAAOC,KAAKC,IAAIN,EAAa,OAAO,IAAII,OAAOC,KAAKC,IAAIJ,EAAc,KACtF,CCkBM,MAAOK,UAAkBC,MACbX,eACAY,aAChB,WAAAC,CAAYC,EAAcd,GACxB,MAAMe,EAAUD,aAAeH,MAC3BG,EAAIC,QACJ,GAAGD,IAEPE,MA/BJ,SAA6BD,EAAiBf,GAC5C,IAAKA,EACH,OAAOe,EAET,MAAME,EAAW,GAAGjB,EAAeC,SAASiB,QAAQlB,EAAeC,SAASG,SAM5E,MAAO,GAAGW,IALWf,EAAemB,SAChC,KAAKnB,EAAemB,YAAYF,IAChC,cAAcA,QACIjB,EAAeE,SACbH,EAAcC,IAExC,CAoBUoB,CAAoBL,EAASf,IACnCqB,KAAKT,aAAeG,EACpBM,KAAKrB,eAAiBA,EACtBsB,OAAOC,eAAeF,KAAMX,EAAUc,WACtCH,KAAKI,KAAO,WACb,CAEM,aAAA1B,GACL,OAAOsB,KAAKrB,gBAAkBD,EAAcsB,KAAKrB,eAClD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EnD,KAAM,YACbgE,IAAK,CAAEhE,KAAM,OACbgD,KAAM,CAAEhD,KAAM,MAAOqD,MAAM,IAE7BC,SAAU,CACR,CAAEC,cAAe,CAAC,MAAO,QACzB,CAAEA,cAAe,CAAC,MAAO,MAAO,UAElCC,YAAa,0HACbC,QAAS,CAAC,WAAY,cACtBC,SAAU,CACR,0DACA,6DACA,6DACA,iEACA,iEACA,oEACA"}
1
+ {"version":3,"file":"functional.esm.js","sources":["../../src/utils/debug/getCodeMarker.ts","../../src/errors.ts","../../src/constants/constants.ts","../../src/utils/symbols.ts","../../src/utils/debug/debugTools.ts","../../src/typeGuards/litsFunction.ts","../../src/typeGuards/lits.ts","../../src/utils/getAssertionError.ts","../../src/utils/debug/getSourceCodeInfo.ts","../../src/utils/arity.ts","../../src/builtin/modules/functional/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 { 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 './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'\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 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 { Arr } from '../../../interface'\nimport type {\n ComplementFunction,\n EveryPredFunction,\n FNullFunction,\n FunctionLike,\n JuxtFunction,\n SomePredFunction,\n} from '../../../parser/types'\nimport { getArityFromFunction, getCommonArityFromFunctions, toFixedArity } from '../../../utils/arity'\nimport { FUNCTION_SYMBOL } from '../../../utils/symbols'\nimport type { BuiltinNormalExpressions } from '../../interface'\nimport { asFunctionLike, assertFunctionLike } from '../../../typeGuards/lits'\nimport { LitsError } from '../../../errors'\nimport type { LitsModule } from '../interface'\n\nconst functionalUtilsNormalExpression: BuiltinNormalExpressions = {\n 'juxt': {\n evaluate: (params, sourceCodeInfo): JuxtFunction => {\n params.forEach(param => assertFunctionLike(param, sourceCodeInfo))\n const arity = getCommonArityFromFunctions(params as FunctionLike[])\n if (arity === null) {\n throw new LitsError('All functions must accept the same number of arguments', sourceCodeInfo)\n }\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'Juxt',\n params,\n arity,\n }\n },\n arity: { min: 1 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n a: { type: 'function' },\n b: { type: 'function' },\n fun: { type: 'function' },\n fns: { type: 'function', rest: true },\n },\n variants: [\n { argumentNames: ['fun'] },\n { argumentNames: ['fun', 'fns'] },\n ],\n description: `Takes one or many function and returns a function that is the juxtaposition of those functions.\nThe returned function takes a variable number of args,\nand returns a vector containing the result of applying each function to the args (left-to-right).`,\n seeAlso: ['comp'],\n examples: [\n `let { juxt } = import(\"functional\");\njuxt(+, *, min, max)(\n 3,\n 4,\n 6,\n)`,\n `let { juxt } = import(\"functional\");\njuxt(\"a\", \"b\")(\n {\n a: 1,\n b: 2,\n c: 3,\n d: 4\n }\n)`,\n `let { juxt } = import(\"functional\");\njuxt(+, *, min, max) apply range(1, 11)`,\n ],\n },\n },\n\n 'complement': {\n evaluate: ([fn], sourceCodeInfo): ComplementFunction => {\n const fun = asFunctionLike(fn, sourceCodeInfo)\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'Complement',\n function: fun,\n arity: getArityFromFunction(fun),\n }\n },\n arity: toFixedArity(1),\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: { fun: { type: 'function' } },\n variants: [{ argumentNames: ['fun'] }],\n description: 'Takes a function $fun and returns a new function that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value.',\n seeAlso: ['comp', 'functional.every-pred', 'functional.some-pred'],\n examples: [\n 'let { complement } = import(\"functional\");\\ncomplement(>)(1, 3)',\n 'let { complement } = import(\"functional\");\\ncomplement(<)(1, 3)',\n 'let { complement } = import(\"functional\");\\ncomplement(+)(1, 3)',\n 'let { complement } = import(\"functional\");\\ncomplement(+)(0, 0)',\n ],\n },\n },\n\n 'every-pred': {\n evaluate: (params, sourceCodeInfo): EveryPredFunction => {\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'EveryPred',\n params,\n arity: { min: 1, max: 1 },\n }\n },\n arity: { min: 1 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n fun: { type: 'function' },\n fns: { type: 'function', rest: true },\n },\n variants: [\n { argumentNames: ['fun'] },\n { argumentNames: ['fun', 'fns'] },\n ],\n description: `\nTakes a number of predicates and returns a function that returns \\`true\\` if all predicates\nreturn a truthy value against all of its arguments, else it returns \\`false\\`.`,\n seeAlso: ['functional.some-pred', 'functional.complement', 'collection.every?'],\n examples: [\n `let { every-pred } = import(\"functional\");\nevery-pred(string?, -> count($) > 3)(\n \"Albert\",\n \"Mojir\"\n)`,\n `let { every-pred } = import(\"functional\");\n(string? every-pred -> count($) > 3)(\n \"Albert\",\n \"M\"\n)`,\n ],\n hideOperatorForm: true,\n },\n },\n\n 'some-pred': {\n evaluate: (params, sourceCodeInfo): SomePredFunction => {\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'SomePred',\n params,\n arity: { min: 1, max: 1 },\n }\n },\n arity: { min: 1 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n fun: { type: 'function' },\n fns: { type: 'function', rest: true },\n },\n variants: [\n { argumentNames: ['fun'] },\n { argumentNames: ['fun', 'fns'] },\n ],\n description: 'Takes a number of `predicates` and returns a function that returns `true` if at least one of the `predicates` return a truthy `true` value against at least one of its arguments, else it returns `false`.',\n seeAlso: ['functional.every-pred', 'functional.complement', 'collection.any?'],\n examples: [\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)(\"Albert\", \"Mojir\")',\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)(\"a\", \"M\")',\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)(\"a\", [1, 2, 3])',\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)([1, 2, 3], [2])',\n ],\n hideOperatorForm: true,\n },\n },\n\n 'fnull': {\n evaluate: ([fn, ...params]: Arr, sourceCodeInfo): FNullFunction => {\n const fun = asFunctionLike(fn, sourceCodeInfo)\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'Fnull',\n function: fun,\n params,\n arity: getArityFromFunction(fun),\n }\n },\n arity: { min: 2 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n a: { type: 'function' },\n b: { type: 'any' },\n fun: { type: 'function' },\n arg: { type: 'any' },\n args: { type: 'any', rest: true },\n },\n variants: [\n { argumentNames: ['fun', 'arg'] },\n { argumentNames: ['fun', 'arg', 'args'] },\n ],\n description: 'Takes a function $fun, and returns a function that calls $fun, replacing a null argument to the corresponding argument.',\n seeAlso: ['identity', 'constantly'],\n examples: [\n 'let { fnull } = import(\"functional\");\\nfnull(inc, 0)(1)',\n 'let { fnull } = import(\"functional\");\\nfnull(inc, 0)(null)',\n 'let { fnull } = import(\"functional\");\\n(inc fnull 0)(null)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(null, 0)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(0, null)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(null, null)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(null, null, 3, 4)',\n ],\n },\n },\n}\n\nexport const functionalUtilsModule: LitsModule = {\n name: 'functional',\n functions: functionalUtilsNormalExpression,\n}\n"],"names":["getCodeMarker","sourceCodeInfo","position","code","leftPadding","column","rightPadding","length","repeat","Math","max","LitsError","Error","shortMessage","constructor","err","message","super","location","line","filePath","getLitsErrorMessage","this","Object","setPrototypeOf","prototype","name","NodeTypes","Number","String","NormalExpression","SpecialExpression","UserDefinedSymbol","NormalBuiltinSymbol","SpecialBuiltinSymbol","ReservedSymbol","Binding","Spread","NodeTypesSet","Set","values","functionTypeSet","FUNCTION_SYMBOL","REGEXP_SYMBOL","isLitsFunction","func","type","functionType","has","isNode","value","Array","isArray","valueToString","keys","find","key","RegExp","toString","JSON","stringify","isObj","regexp","isColl","isSeq","asFunctionLike","assertFunctionLike","isFunctionLike","typeName","anyValue","getSourceCodeInfo","getAssertionError","getArityFromFunction","param","toFixedArity","arity","min","functionalUtilsModule","functions","juxt","evaluate","params","forEach","reduce","acc","aMin","aMax","bMin","bMax","undefined","getCommonArityFromFunctions","docs","category","returns","args","a","b","fun","fns","rest","variants","argumentNames","description","seeAlso","examples","complement","fn","function","hideOperatorForm","fnull","arg"],"mappings":"AAEM,SAAUA,EAAcC,GAC5B,IAAKA,EAAeC,WAAaD,EAAeE,KAC9C,MAAO,GAET,MAAMC,EAAcH,EAAeC,SAASG,OAAS,EAC/CC,EAA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AO,CAAEC,IAAK,GACde,KAAM,CACJC,SAAU,aACVC,QAAS,CAAE/C,KAAM,YACjBgD,KAAM,CACJG,IAAK,CAAEnD,KAAM,YACboD,IAAK,CAAEpD,KAAM,WAAYqD,MAAM,IAEjCC,SAAU,CACR,CAAEC,cAAe,CAAC,QAClB,CAAEA,cAAe,CAAC,MAAO,SAE3BC,YAAa,6MACbC,QAAS,CAAC,wBAAyB,wBAAyB,mBAC5DC,SAAU,CACR,oGACA,2FACA,iGACA,kGAEFI,kBAAkB,IAItBC,MAAS,CACP7B,SAAU,EAAE0B,KAAOzB,GAAchF,KAC/B,MAAMgG,EAAMhC,EAAeyC,EAAIzG,GAC/B,MAAO,CACLyC,CAACA,IAAkB,EACnBzC,iBACA8C,aAAc,QACd4D,SAAUV,EACVhB,SACAN,MAAOH,EAAqByB,KAGhCtB,MAAO,CAAEC,IAAK,GACde,KAAM,CACJC,SAAU,aACVC,QAAS,CAAE/C,KAAM,YACjBgD,KAAM,CACJC,EAAG,CAAEjD,KAAM,YACXkD,EAAG,CAAElD,KAAM,OACXmD,IAAK,CAAEnD,KAAM,YACbgE,IAAK,CAAEhE,KAAM,OACbgD,KAAM,CAAEhD,KAAM,MAAOqD,MAAM,IAE7BC,SAAU,CACR,CAAEC,cAAe,CAAC,MAAO,QACzB,CAAEA,cAAe,CAAC,MAAO,MAAO,UAElCC,YAAa,0HACbC,QAAS,CAAC,WAAY,cACtBC,SAAU,CACR,0DACA,6DACA,6DACA,iEACA,iEACA,oEACA"}
@@ -1 +1 @@
1
- {"version":3,"file":"functional.js","sources":["../../src/utils/debug/getCodeMarker.ts","../../src/errors.ts","../../src/constants/constants.ts","../../src/utils/symbols.ts","../../src/utils/debug/debugTools.ts","../../src/typeGuards/litsFunction.ts","../../src/typeGuards/lits.ts","../../src/utils/getAssertionError.ts","../../src/utils/debug/getSourceCodeInfo.ts","../../src/utils/arity.ts","../../src/builtin/modules/functional/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 { LitsFunction, Node } 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 Node {\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 { 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\nexport function 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 './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'\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 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 { Arr } from '../../../interface'\nimport type {\n ComplementFunction,\n EveryPredFunction,\n FNullFunction,\n FunctionLike,\n JuxtFunction,\n SomePredFunction,\n} from '../../../parser/types'\nimport { getArityFromFunction, getCommonArityFromFunctions, toFixedArity } from '../../../utils/arity'\nimport { FUNCTION_SYMBOL } from '../../../utils/symbols'\nimport type { BuiltinNormalExpressions } from '../../interface'\nimport { asFunctionLike, assertFunctionLike } from '../../../typeGuards/lits'\nimport { LitsError } from '../../../errors'\nimport type { LitsModule } from '../interface'\n\nconst functionalUtilsNormalExpression: BuiltinNormalExpressions = {\n 'juxt': {\n evaluate: (params, sourceCodeInfo): JuxtFunction => {\n params.forEach(param => assertFunctionLike(param, sourceCodeInfo))\n const arity = getCommonArityFromFunctions(params as FunctionLike[])\n if (arity === null) {\n throw new LitsError('All functions must accept the same number of arguments', sourceCodeInfo)\n }\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'Juxt',\n params,\n arity,\n }\n },\n arity: { min: 1 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n a: { type: 'function' },\n b: { type: 'function' },\n fun: { type: 'function' },\n fns: { type: 'function', rest: true },\n },\n variants: [\n { argumentNames: ['fun'] },\n { argumentNames: ['fun', 'fns'] },\n ],\n description: `Takes one or many function and returns a function that is the juxtaposition of those functions.\nThe returned function takes a variable number of args,\nand returns a vector containing the result of applying each function to the args (left-to-right).`,\n seeAlso: ['comp'],\n examples: [\n `let { juxt } = import(\"functional\");\njuxt(+, *, min, max)(\n 3,\n 4,\n 6,\n)`,\n `let { juxt } = import(\"functional\");\njuxt(\"a\", \"b\")(\n {\n a: 1,\n b: 2,\n c: 3,\n d: 4\n }\n)`,\n `let { juxt } = import(\"functional\");\njuxt(+, *, min, max) apply range(1, 11)`,\n ],\n },\n },\n\n 'complement': {\n evaluate: ([fn], sourceCodeInfo): ComplementFunction => {\n const fun = asFunctionLike(fn, sourceCodeInfo)\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'Complement',\n function: fun,\n arity: getArityFromFunction(fun),\n }\n },\n arity: toFixedArity(1),\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: { fun: { type: 'function' } },\n variants: [{ argumentNames: ['fun'] }],\n description: 'Takes a function $fun and returns a new function that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value.',\n seeAlso: ['comp', 'functional.every-pred', 'functional.some-pred'],\n examples: [\n 'let { complement } = import(\"functional\");\\ncomplement(>)(1, 3)',\n 'let { complement } = import(\"functional\");\\ncomplement(<)(1, 3)',\n 'let { complement } = import(\"functional\");\\ncomplement(+)(1, 3)',\n 'let { complement } = import(\"functional\");\\ncomplement(+)(0, 0)',\n ],\n },\n },\n\n 'every-pred': {\n evaluate: (params, sourceCodeInfo): EveryPredFunction => {\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'EveryPred',\n params,\n arity: { min: 1, max: 1 },\n }\n },\n arity: { min: 1 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n fun: { type: 'function' },\n fns: { type: 'function', rest: true },\n },\n variants: [\n { argumentNames: ['fun'] },\n { argumentNames: ['fun', 'fns'] },\n ],\n description: `\nTakes a number of predicates and returns a function that returns \\`true\\` if all predicates\nreturn a truthy value against all of its arguments, else it returns \\`false\\`.`,\n seeAlso: ['functional.some-pred', 'functional.complement', 'collection.every?'],\n examples: [\n `let { every-pred } = import(\"functional\");\nevery-pred(string?, -> count($) > 3)(\n \"Albert\",\n \"Mojir\"\n)`,\n `let { every-pred } = import(\"functional\");\n(string? every-pred -> count($) > 3)(\n \"Albert\",\n \"M\"\n)`,\n ],\n hideOperatorForm: true,\n },\n },\n\n 'some-pred': {\n evaluate: (params, sourceCodeInfo): SomePredFunction => {\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'SomePred',\n params,\n arity: { min: 1, max: 1 },\n }\n },\n arity: { min: 1 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n fun: { type: 'function' },\n fns: { type: 'function', rest: true },\n },\n variants: [\n { argumentNames: ['fun'] },\n { argumentNames: ['fun', 'fns'] },\n ],\n description: 'Takes a number of `predicates` and returns a function that returns `true` if at least one of the `predicates` return a truthy `true` value against at least one of its arguments, else it returns `false`.',\n seeAlso: ['functional.every-pred', 'functional.complement', 'collection.any?'],\n examples: [\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)(\"Albert\", \"Mojir\")',\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)(\"a\", \"M\")',\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)(\"a\", [1, 2, 3])',\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)([1, 2, 3], [2])',\n ],\n hideOperatorForm: true,\n },\n },\n\n 'fnull': {\n evaluate: ([fn, ...params]: Arr, sourceCodeInfo): FNullFunction => {\n const fun = asFunctionLike(fn, sourceCodeInfo)\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'Fnull',\n function: fun,\n params,\n arity: getArityFromFunction(fun),\n }\n },\n arity: { min: 2 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n a: { type: 'function' },\n b: { type: 'any' },\n fun: { type: 'function' },\n arg: { type: 'any' },\n args: { type: 'any', rest: true },\n },\n variants: [\n { argumentNames: ['fun', 'arg'] },\n { argumentNames: ['fun', 'arg', 'args'] },\n ],\n description: 'Takes a function $fun, and returns a function that calls $fun, replacing a null argument to the corresponding argument.',\n seeAlso: ['identity', 'constantly'],\n examples: [\n 'let { fnull } = import(\"functional\");\\nfnull(inc, 0)(1)',\n 'let { fnull } = import(\"functional\");\\nfnull(inc, 0)(null)',\n 'let { fnull } = import(\"functional\");\\n(inc fnull 0)(null)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(null, 0)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(0, null)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(null, null)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(null, null, 3, 4)',\n ],\n },\n },\n}\n\nexport const functionalUtilsModule: LitsModule = {\n name: 'functional',\n functions: functionalUtilsNormalExpression,\n}\n"],"names":["getCodeMarker","sourceCodeInfo","position","code","leftPadding","column","rightPadding","length","repeat","Math","max","LitsError","Error","shortMessage","constructor","err","message","super","location","line","filePath","getLitsErrorMessage","this","Object","setPrototypeOf","prototype","name","NodeTypes","Number","String","NormalExpression","SpecialExpression","UserDefinedSymbol","NormalBuiltinSymbol","SpecialBuiltinSymbol","ReservedSymbol","Binding","Spread","NodeTypesSet","Set","values","functionTypeSet","FUNCTION_SYMBOL","REGEXP_SYMBOL","isLitsFunction","func","type","functionType","has","isNode","value","Array","isArray","valueToString","keys","find","key","RegExp","toString","JSON","stringify","isObj","regexp","isColl","isSeq","asFunctionLike","assertFunctionLike","isFunctionLike","typeName","anyValue","getSourceCodeInfo","getAssertionError","getArityFromFunction","param","toFixedArity","arity","min","functionalUtilsModule","functions","juxt","evaluate","params","forEach","reduce","acc","aMin","aMax","bMin","bMax","undefined","getCommonArityFromFunctions","docs","category","returns","args","a","b","fun","fns","rest","variants","argumentNames","description","seeAlso","examples","complement","fn","function","hideOperatorForm","fnull","arg"],"mappings":"aAEM,SAAUA,EAAcC,GAC5B,IAAKA,EAAeC,WAAaD,EAAeE,KAC9C,MAAO,GAET,MAAMC,EAAcH,EAAeC,SAASG,OAAS,EAC/CC,EAAeL,EAAeE,KAAKI,OAASH,EAAc,EAChE,MAAO,GAAG,IAAII,OAAOC,KAAKC,IAAIN,EAAa,OAAO,IAAII,OAAOC,KAAKC,IAAIJ,EAAc,KACtF,CCkBM,MAAOK,UAAkBC,MACbX,eACAY,aAChB,WAAAC,CAAYC,EAAcd,GACxB,MAAMe,EAAUD,aAAeH,MAC3BG,EAAIC,QACJ,GAAGD,IAEPE,MA/BJ,SAA6BD,EAAiBf,GAC5C,IAAKA,EACH,OAAOe,EAET,MAAME,EAAW,GAAGjB,EAAeC,SAASiB,QAAQlB,EAAeC,SAASG,SAM5E,MAAO,GAAGW,IALWf,EAAemB,SAChC,KAAKnB,EAAemB,YAAYF,IAChC,cAAcA,QACIjB,EAAeE,SACbH,EAAcC,IAExC,CAoBUoB,CAAoBL,EAASf,IACnCqB,KAAKT,aAAeG,EACpBM,KAAKrB,eAAiBA,E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KAAM,CACJC,SAAU,aACVC,QAAS,CAAE/C,KAAM,YACjBgD,KAAM,CACJC,EAAG,CAAEjD,KAAM,YACXkD,EAAG,CAAElD,KAAM,OACXmD,IAAK,CAAEnD,KAAM,YACbgE,IAAK,CAAEhE,KAAM,OACbgD,KAAM,CAAEhD,KAAM,MAAOqD,MAAM,IAE7BC,SAAU,CACR,CAAEC,cAAe,CAAC,MAAO,QACzB,CAAEA,cAAe,CAAC,MAAO,MAAO,UAElCC,YAAa,0HACbC,QAAS,CAAC,WAAY,cACtBC,SAAU,CACR,0DACA,6DACA,6DACA,iEACA,iEACA,oEACA"}
1
+ {"version":3,"file":"functional.js","sources":["../../src/utils/debug/getCodeMarker.ts","../../src/errors.ts","../../src/constants/constants.ts","../../src/utils/symbols.ts","../../src/utils/debug/debugTools.ts","../../src/typeGuards/litsFunction.ts","../../src/typeGuards/lits.ts","../../src/utils/getAssertionError.ts","../../src/utils/debug/getSourceCodeInfo.ts","../../src/utils/arity.ts","../../src/builtin/modules/functional/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 { 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 './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'\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 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 { Arr } from '../../../interface'\nimport type {\n ComplementFunction,\n EveryPredFunction,\n FNullFunction,\n FunctionLike,\n JuxtFunction,\n SomePredFunction,\n} from '../../../parser/types'\nimport { getArityFromFunction, getCommonArityFromFunctions, toFixedArity } from '../../../utils/arity'\nimport { FUNCTION_SYMBOL } from '../../../utils/symbols'\nimport type { BuiltinNormalExpressions } from '../../interface'\nimport { asFunctionLike, assertFunctionLike } from '../../../typeGuards/lits'\nimport { LitsError } from '../../../errors'\nimport type { LitsModule } from '../interface'\n\nconst functionalUtilsNormalExpression: BuiltinNormalExpressions = {\n 'juxt': {\n evaluate: (params, sourceCodeInfo): JuxtFunction => {\n params.forEach(param => assertFunctionLike(param, sourceCodeInfo))\n const arity = getCommonArityFromFunctions(params as FunctionLike[])\n if (arity === null) {\n throw new LitsError('All functions must accept the same number of arguments', sourceCodeInfo)\n }\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'Juxt',\n params,\n arity,\n }\n },\n arity: { min: 1 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n a: { type: 'function' },\n b: { type: 'function' },\n fun: { type: 'function' },\n fns: { type: 'function', rest: true },\n },\n variants: [\n { argumentNames: ['fun'] },\n { argumentNames: ['fun', 'fns'] },\n ],\n description: `Takes one or many function and returns a function that is the juxtaposition of those functions.\nThe returned function takes a variable number of args,\nand returns a vector containing the result of applying each function to the args (left-to-right).`,\n seeAlso: ['comp'],\n examples: [\n `let { juxt } = import(\"functional\");\njuxt(+, *, min, max)(\n 3,\n 4,\n 6,\n)`,\n `let { juxt } = import(\"functional\");\njuxt(\"a\", \"b\")(\n {\n a: 1,\n b: 2,\n c: 3,\n d: 4\n }\n)`,\n `let { juxt } = import(\"functional\");\njuxt(+, *, min, max) apply range(1, 11)`,\n ],\n },\n },\n\n 'complement': {\n evaluate: ([fn], sourceCodeInfo): ComplementFunction => {\n const fun = asFunctionLike(fn, sourceCodeInfo)\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'Complement',\n function: fun,\n arity: getArityFromFunction(fun),\n }\n },\n arity: toFixedArity(1),\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: { fun: { type: 'function' } },\n variants: [{ argumentNames: ['fun'] }],\n description: 'Takes a function $fun and returns a new function that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value.',\n seeAlso: ['comp', 'functional.every-pred', 'functional.some-pred'],\n examples: [\n 'let { complement } = import(\"functional\");\\ncomplement(>)(1, 3)',\n 'let { complement } = import(\"functional\");\\ncomplement(<)(1, 3)',\n 'let { complement } = import(\"functional\");\\ncomplement(+)(1, 3)',\n 'let { complement } = import(\"functional\");\\ncomplement(+)(0, 0)',\n ],\n },\n },\n\n 'every-pred': {\n evaluate: (params, sourceCodeInfo): EveryPredFunction => {\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'EveryPred',\n params,\n arity: { min: 1, max: 1 },\n }\n },\n arity: { min: 1 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n fun: { type: 'function' },\n fns: { type: 'function', rest: true },\n },\n variants: [\n { argumentNames: ['fun'] },\n { argumentNames: ['fun', 'fns'] },\n ],\n description: `\nTakes a number of predicates and returns a function that returns \\`true\\` if all predicates\nreturn a truthy value against all of its arguments, else it returns \\`false\\`.`,\n seeAlso: ['functional.some-pred', 'functional.complement', 'collection.every?'],\n examples: [\n `let { every-pred } = import(\"functional\");\nevery-pred(string?, -> count($) > 3)(\n \"Albert\",\n \"Mojir\"\n)`,\n `let { every-pred } = import(\"functional\");\n(string? every-pred -> count($) > 3)(\n \"Albert\",\n \"M\"\n)`,\n ],\n hideOperatorForm: true,\n },\n },\n\n 'some-pred': {\n evaluate: (params, sourceCodeInfo): SomePredFunction => {\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'SomePred',\n params,\n arity: { min: 1, max: 1 },\n }\n },\n arity: { min: 1 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n fun: { type: 'function' },\n fns: { type: 'function', rest: true },\n },\n variants: [\n { argumentNames: ['fun'] },\n { argumentNames: ['fun', 'fns'] },\n ],\n description: 'Takes a number of `predicates` and returns a function that returns `true` if at least one of the `predicates` return a truthy `true` value against at least one of its arguments, else it returns `false`.',\n seeAlso: ['functional.every-pred', 'functional.complement', 'collection.any?'],\n examples: [\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)(\"Albert\", \"Mojir\")',\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)(\"a\", \"M\")',\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)(\"a\", [1, 2, 3])',\n 'let { some-pred } = import(\"functional\");\\nsome-pred(string?, -> count($) > 3)([1, 2, 3], [2])',\n ],\n hideOperatorForm: true,\n },\n },\n\n 'fnull': {\n evaluate: ([fn, ...params]: Arr, sourceCodeInfo): FNullFunction => {\n const fun = asFunctionLike(fn, sourceCodeInfo)\n return {\n [FUNCTION_SYMBOL]: true,\n sourceCodeInfo,\n functionType: 'Fnull',\n function: fun,\n params,\n arity: getArityFromFunction(fun),\n }\n },\n arity: { min: 2 },\n docs: {\n category: 'functional',\n returns: { type: 'function' },\n args: {\n a: { type: 'function' },\n b: { type: 'any' },\n fun: { type: 'function' },\n arg: { type: 'any' },\n args: { type: 'any', rest: true },\n },\n variants: [\n { argumentNames: ['fun', 'arg'] },\n { argumentNames: ['fun', 'arg', 'args'] },\n ],\n description: 'Takes a function $fun, and returns a function that calls $fun, replacing a null argument to the corresponding argument.',\n seeAlso: ['identity', 'constantly'],\n examples: [\n 'let { fnull } = import(\"functional\");\\nfnull(inc, 0)(1)',\n 'let { fnull } = import(\"functional\");\\nfnull(inc, 0)(null)',\n 'let { fnull } = import(\"functional\");\\n(inc fnull 0)(null)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(null, 0)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(0, null)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(null, null)',\n 'let { fnull } = import(\"functional\");\\nfnull(+, 1, 2)(null, null, 3, 4)',\n ],\n },\n },\n}\n\nexport const functionalUtilsModule: LitsModule = {\n name: 'functional',\n functions: functionalUtilsNormalExpression,\n}\n"],"names":["getCodeMarker","sourceCodeInfo","position","code","leftPadding","column","rightPadding","length","repeat","Math","max","LitsError","Error","shortMessage","constructor","err","message","super","location","line","filePath","getLitsErrorMessage","this","Object","setPrototypeOf","prototype","name","NodeTypes","Number","String","NormalExpression","SpecialExpression","UserDefinedSymbol","NormalBuiltinSymbol","SpecialBuiltinSymbol","ReservedSymbol","Binding","Spread","NodeTypesSet","Set","values","functionTypeSet","FUNCTION_SYMBOL","REGEXP_SYMBOL","isLitsFunction","func","type","functionType","has","isNode","value","Array","isArray","valueToString","keys","find","key","RegExp","toString","JSON","stringify","isObj","regexp","isColl","isSeq","asFunctionLike","assertFunctionLike","isFunctionLike","typeName","anyValue","getSourceCodeInfo","getAssertionError","getArityFromFunction","param","toFixedArity","arity","min","functionalUtilsModule","functions","juxt","evaluate","params","forEach","reduce","acc","aMin","aMax","bMin","bMax","undefined","getCommonArityFromFunctions","docs","category","returns","args","a","b","fun","fns","rest","variants","argumentNames","description","seeAlso","examples","complement","fn","function","hideOperatorForm","fnull","arg"],"m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