@mojir/lits 2.1.11 → 2.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -399,6 +399,8 @@ function isNumber(value, options) {
399
399
  if (options === void 0) { options = {}; }
400
400
  if (typeof value !== 'number')
401
401
  return false;
402
+ if (Number.isNaN(value))
403
+ return false;
402
404
  if (options.integer && !Number.isInteger(value))
403
405
  return false;
404
406
  if (options.finite && !Number.isFinite(value))
@@ -972,6 +974,35 @@ var collectionNormalExpression = {
972
974
  },
973
975
  paramCount: 2,
974
976
  },
977
+ 'filteri': {
978
+ evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
979
+ var _c = __read(_a, 2), coll = _c[0], fn = _c[1];
980
+ var executeFunction = _b.executeFunction;
981
+ assertColl(coll, sourceCodeInfo);
982
+ assertFunctionLike(fn, sourceCodeInfo);
983
+ if (Array.isArray(coll)) {
984
+ var result = coll.filter(function (elem, index) { return executeFunction(fn, [elem, index], contextStack, sourceCodeInfo); });
985
+ return result;
986
+ }
987
+ if (isString(coll)) {
988
+ return coll
989
+ .split('')
990
+ .filter(function (elem, index) { return executeFunction(fn, [elem, index], contextStack, sourceCodeInfo); })
991
+ .join('');
992
+ }
993
+ return Object.entries(coll)
994
+ .filter(function (_a) {
995
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
996
+ return executeFunction(fn, [value, key], contextStack, sourceCodeInfo);
997
+ })
998
+ .reduce(function (result, _a) {
999
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
1000
+ result[key] = value;
1001
+ return result;
1002
+ }, {});
1003
+ },
1004
+ paramCount: 2,
1005
+ },
975
1006
  'map': {
976
1007
  evaluate: function (params, sourceCodeInfo, contextStack, _a) {
977
1008
  var executeFunction = _a.executeFunction;
@@ -1014,6 +1045,30 @@ var collectionNormalExpression = {
1014
1045
  },
1015
1046
  paramCount: { min: 2 },
1016
1047
  },
1048
+ 'mapi': {
1049
+ evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
1050
+ var _c = __read(_a, 2), coll = _c[0], fn = _c[1];
1051
+ var executeFunction = _b.executeFunction;
1052
+ assertColl(coll, sourceCodeInfo);
1053
+ assertFunctionLike(fn, sourceCodeInfo);
1054
+ if (Array.isArray(coll)) {
1055
+ return coll.map(function (elem, index) { return executeFunction(fn, [elem, index], contextStack, sourceCodeInfo); });
1056
+ }
1057
+ if (isString(coll)) {
1058
+ return coll
1059
+ .split('')
1060
+ .map(function (elem, index) { return executeFunction(fn, [elem, index], contextStack, sourceCodeInfo); })
1061
+ .join('');
1062
+ }
1063
+ return Object.entries(coll)
1064
+ .reduce(function (acc, _a) {
1065
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
1066
+ acc[key] = executeFunction(fn, [value, key], contextStack, sourceCodeInfo);
1067
+ return acc;
1068
+ }, {});
1069
+ },
1070
+ paramCount: 2,
1071
+ },
1017
1072
  'reduce': {
1018
1073
  evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
1019
1074
  var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
@@ -1047,6 +1102,39 @@ var collectionNormalExpression = {
1047
1102
  },
1048
1103
  paramCount: 3,
1049
1104
  },
1105
+ 'reducei': {
1106
+ evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
1107
+ var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
1108
+ var executeFunction = _b.executeFunction;
1109
+ assertColl(coll, sourceCodeInfo);
1110
+ assertFunctionLike(fn, sourceCodeInfo);
1111
+ assertAny(initial, sourceCodeInfo);
1112
+ if (typeof coll === 'string') {
1113
+ assertString(initial, sourceCodeInfo);
1114
+ if (coll.length === 0)
1115
+ return initial;
1116
+ return coll.split('').reduce(function (result, elem, index) {
1117
+ return executeFunction(fn, [result, elem, index], contextStack, sourceCodeInfo);
1118
+ }, initial);
1119
+ }
1120
+ else if (Array.isArray(coll)) {
1121
+ if (coll.length === 0)
1122
+ return initial;
1123
+ return coll.reduce(function (result, elem, index) {
1124
+ return executeFunction(fn, [result, elem, index], contextStack, sourceCodeInfo);
1125
+ }, initial);
1126
+ }
1127
+ else {
1128
+ if (Object.keys(coll).length === 0)
1129
+ return initial;
1130
+ return Object.entries(coll).reduce(function (result, _a) {
1131
+ var _b = __read(_a, 2), key = _b[0], elem = _b[1];
1132
+ return executeFunction(fn, [result, elem, key], contextStack, sourceCodeInfo);
1133
+ }, initial);
1134
+ }
1135
+ },
1136
+ paramCount: 3,
1137
+ },
1050
1138
  'reduce-right': {
1051
1139
  evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
1052
1140
  var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
@@ -1079,6 +1167,38 @@ var collectionNormalExpression = {
1079
1167
  },
1080
1168
  paramCount: 3,
1081
1169
  },
1170
+ 'reducei-right': {
1171
+ evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
1172
+ var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
1173
+ var executeFunction = _b.executeFunction;
1174
+ assertColl(coll, sourceCodeInfo);
1175
+ assertFunctionLike(fn, sourceCodeInfo);
1176
+ assertAny(initial, sourceCodeInfo);
1177
+ if (typeof coll === 'string') {
1178
+ if (coll.length === 0)
1179
+ return initial;
1180
+ return coll.split('').reduceRight(function (result, elem, index) {
1181
+ return executeFunction(fn, [result, elem, index], contextStack, sourceCodeInfo);
1182
+ }, initial);
1183
+ }
1184
+ else if (Array.isArray(coll)) {
1185
+ if (coll.length === 0)
1186
+ return initial;
1187
+ return coll.reduceRight(function (result, elem, index) {
1188
+ return executeFunction(fn, [result, elem, index], contextStack, sourceCodeInfo);
1189
+ }, initial);
1190
+ }
1191
+ else {
1192
+ if (Object.keys(coll).length === 0)
1193
+ return initial;
1194
+ return Object.entries(coll).reduceRight(function (result, _a) {
1195
+ var _b = __read(_a, 2), key = _b[0], elem = _b[1];
1196
+ return executeFunction(fn, [result, elem, key], contextStack, sourceCodeInfo);
1197
+ }, initial);
1198
+ }
1199
+ },
1200
+ paramCount: 3,
1201
+ },
1082
1202
  'reductions': {
1083
1203
  evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
1084
1204
  var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
@@ -1125,6 +1245,52 @@ var collectionNormalExpression = {
1125
1245
  },
1126
1246
  paramCount: 3,
1127
1247
  },
1248
+ 'reductionsi': {
1249
+ evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
1250
+ var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
1251
+ var executeFunction = _b.executeFunction;
1252
+ assertColl(coll, sourceCodeInfo);
1253
+ assertFunctionLike(fn, sourceCodeInfo);
1254
+ assertAny(initial, sourceCodeInfo);
1255
+ assertAny(initial, sourceCodeInfo);
1256
+ if (typeof coll === 'string') {
1257
+ assertString(initial, sourceCodeInfo);
1258
+ if (coll.length === 0)
1259
+ return [initial];
1260
+ var resultArray_4 = [initial];
1261
+ coll.split('').reduce(function (result, elem, index) {
1262
+ var newVal = executeFunction(fn, [result, elem, index], contextStack, sourceCodeInfo);
1263
+ resultArray_4.push(newVal);
1264
+ return newVal;
1265
+ }, initial);
1266
+ return resultArray_4;
1267
+ }
1268
+ else if (Array.isArray(coll)) {
1269
+ if (coll.length === 0)
1270
+ return [initial];
1271
+ var resultArray_5 = [initial];
1272
+ coll.reduce(function (result, elem, index) {
1273
+ var newVal = executeFunction(fn, [result, elem, index], contextStack, sourceCodeInfo);
1274
+ resultArray_5.push(newVal);
1275
+ return newVal;
1276
+ }, initial);
1277
+ return resultArray_5;
1278
+ }
1279
+ else {
1280
+ if (Object.keys(coll).length === 0)
1281
+ return [initial];
1282
+ var resultArray_6 = [initial];
1283
+ Object.entries(coll).reduce(function (result, _a) {
1284
+ var _b = __read(_a, 2), key = _b[0], elem = _b[1];
1285
+ var newVal = executeFunction(fn, [result, elem, key], contextStack, sourceCodeInfo);
1286
+ resultArray_6.push(newVal);
1287
+ return newVal;
1288
+ }, initial);
1289
+ return resultArray_6;
1290
+ }
1291
+ },
1292
+ paramCount: 3,
1293
+ },
1128
1294
  'get': {
1129
1295
  evaluate: function (params, sourceCodeInfo) {
1130
1296
  var _a = __read(params, 2), coll = _a[0], key = _a[1];
@@ -1378,7 +1544,7 @@ var collectionNormalExpression = {
1378
1544
  };
1379
1545
 
1380
1546
  var arrayNormalExpression = {
1381
- range: {
1547
+ 'range': {
1382
1548
  evaluate: function (params, sourceCodeInfo) {
1383
1549
  var _a = __read(params, 3), first = _a[0], second = _a[1], third = _a[2];
1384
1550
  var from;
@@ -1416,7 +1582,7 @@ var arrayNormalExpression = {
1416
1582
  },
1417
1583
  paramCount: { min: 1, max: 3 },
1418
1584
  },
1419
- repeat: {
1585
+ 'repeat': {
1420
1586
  evaluate: function (_a, sourceCodeInfo) {
1421
1587
  var _b = __read(_a, 2), value = _b[0], count = _b[1];
1422
1588
  assertNumber(count, sourceCodeInfo, { integer: true, nonNegative: true });
@@ -1427,7 +1593,7 @@ var arrayNormalExpression = {
1427
1593
  },
1428
1594
  paramCount: 2,
1429
1595
  },
1430
- flatten: {
1596
+ 'flatten': {
1431
1597
  evaluate: function (_a, sourceCodeInfo) {
1432
1598
  var _b = __read(_a, 2), seq = _b[0], depth = _b[1];
1433
1599
  assertArray(seq, sourceCodeInfo);
@@ -1438,7 +1604,7 @@ var arrayNormalExpression = {
1438
1604
  },
1439
1605
  paramCount: { min: 1, max: 2 },
1440
1606
  },
1441
- mapcat: {
1607
+ 'mapcat': {
1442
1608
  evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
1443
1609
  var _c = __read(_a, 2), arr = _c[0], fn = _c[1];
1444
1610
  var executeFunction = _b.executeFunction;
@@ -1448,6 +1614,38 @@ var arrayNormalExpression = {
1448
1614
  },
1449
1615
  paramCount: 2,
1450
1616
  },
1617
+ 'moving-fn': {
1618
+ evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
1619
+ var _c = __read(_a, 3), arr = _c[0], windowSize = _c[1], fn = _c[2];
1620
+ var executeFunction = _b.executeFunction;
1621
+ assertArray(arr, sourceCodeInfo);
1622
+ assertNumber(windowSize, sourceCodeInfo, { integer: true, lte: arr.length });
1623
+ assertFunctionLike(fn, sourceCodeInfo);
1624
+ var result = [];
1625
+ for (var i = 0; i <= arr.length - windowSize; i++) {
1626
+ var window_1 = arr.slice(i, i + windowSize);
1627
+ var value = executeFunction(fn, [window_1], contextStack, sourceCodeInfo);
1628
+ result.push(value);
1629
+ }
1630
+ return result;
1631
+ },
1632
+ paramCount: 3,
1633
+ },
1634
+ 'running-fn': {
1635
+ evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
1636
+ var _c = __read(_a, 2), arr = _c[0], fn = _c[1];
1637
+ var executeFunction = _b.executeFunction;
1638
+ assertArray(arr, sourceCodeInfo);
1639
+ assertFunctionLike(fn, sourceCodeInfo);
1640
+ var result = [];
1641
+ for (var i = 0; i < arr.length; i += 1) {
1642
+ var subArr = arr.slice(0, i + 1);
1643
+ result.push(executeFunction(fn, [subArr], contextStack, sourceCodeInfo));
1644
+ }
1645
+ return result;
1646
+ },
1647
+ paramCount: 2,
1648
+ },
1451
1649
  };
1452
1650
 
1453
1651
  var sequenceNormalExpression = {
@@ -2179,7 +2377,7 @@ function isVector(vector) {
2179
2377
  if (vectors.has(vector)) {
2180
2378
  return true;
2181
2379
  }
2182
- if (vector.every(function (elem) { return isNumber(elem, { finite: true }); })) {
2380
+ if (vector.every(function (elem) { return isNumber(elem); })) {
2183
2381
  annotatedArrays.add(vector);
2184
2382
  vectors.add(vector);
2185
2383
  return true;
@@ -2288,7 +2486,7 @@ function isMatrix(matrix) {
2288
2486
  if (row.length !== nbrOfCols) {
2289
2487
  return false;
2290
2488
  }
2291
- if (row.some(function (cell) { return !isNumber(cell, { finite: true }); })) {
2489
+ if (row.some(function (cell) { return !isNumber(cell); })) {
2292
2490
  return false;
2293
2491
  }
2294
2492
  }
@@ -3821,14 +4019,6 @@ var predicatesNormalExpression = {
3821
4019
  },
3822
4020
  paramCount: 1,
3823
4021
  },
3824
- 'nan?': {
3825
- evaluate: function (_a, sourceCodeInfo) {
3826
- var _b = __read(_a, 1), value = _b[0];
3827
- assertNumber(value, sourceCodeInfo);
3828
- return Number.isNaN(value);
3829
- },
3830
- paramCount: 1,
3831
- },
3832
4022
  'positive-infinity?': {
3833
4023
  evaluate: function (_a, sourceCodeInfo) {
3834
4024
  var _b = __read(_a, 1), value = _b[0];
@@ -12545,8 +12735,13 @@ function evaluateNode(node, contextStack) {
12545
12735
  return contextStack.evaluateSymbol(node);
12546
12736
  case NodeTypes.ReservedSymbol:
12547
12737
  return evaluateReservedSymbol(node);
12548
- case NodeTypes.NormalExpression:
12549
- return annotate(evaluateNormalExpression(node, contextStack));
12738
+ case NodeTypes.NormalExpression: {
12739
+ var result = evaluateNormalExpression(node, contextStack);
12740
+ if (typeof result === 'number' && Number.isNaN(result)) {
12741
+ throw new LitsError('Number is NaN', node[2]);
12742
+ }
12743
+ return annotate(result);
12744
+ }
12550
12745
  case NodeTypes.SpecialExpression:
12551
12746
  return annotate(evaluateSpecialExpression(node, contextStack));
12552
12747
  /* v8 ignore next 2 */
@@ -12938,6 +13133,8 @@ var binaryOperators = [
12938
13133
  '|>', // pipe
12939
13134
  ];
12940
13135
  var otherOperators = [
13136
+ '?', // conditional operator
13137
+ ':', // conditional operator
12941
13138
  '->', // lambda
12942
13139
  '...', // rest
12943
13140
  '.', // property accessor
@@ -12947,17 +13144,12 @@ var otherOperators = [
12947
13144
  ];
12948
13145
  var symbolicOperators = __spreadArray(__spreadArray([], __read(binaryOperators), false), __read(otherOperators), false);
12949
13146
  var nonFunctionOperators = [
12950
- '??',
12951
- '&&',
12952
- '||',
12953
13147
  'comment',
12954
13148
  'cond',
12955
13149
  'def',
12956
13150
  'defined?',
12957
- // 'defn',
12958
13151
  'do',
12959
13152
  'doseq',
12960
- // 'fn',
12961
13153
  'if',
12962
13154
  'let',
12963
13155
  'loop',
@@ -13535,8 +13727,9 @@ function untokenize(tokenStream) {
13535
13727
  }, '');
13536
13728
  }
13537
13729
 
13538
- var exponentiationPrecedence = 11;
13539
- var binaryFunctionalOperatorPrecedence = 2;
13730
+ var exponentiationPrecedence = 12;
13731
+ var binaryFunctionalOperatorPrecedence = 3;
13732
+ var conditionalOperatorPrecedence = 1;
13540
13733
  var placeholderRegexp = /^\$([1-9]\d?)?$/;
13541
13734
  function withSourceCodeInfo(node, sourceCodeInfo) {
13542
13735
  if (sourceCodeInfo) {
@@ -13551,38 +13744,39 @@ function getPrecedence(operatorSign, sourceCodeInfo) {
13551
13744
  case '*': // multiplication
13552
13745
  case '/': // division
13553
13746
  case '%': // remainder
13554
- return 10;
13747
+ return 11;
13555
13748
  case '+': // addition
13556
13749
  case '-': // subtraction
13557
- return 9;
13750
+ return 10;
13558
13751
  case '<<': // left shift
13559
13752
  case '>>': // signed right shift
13560
13753
  case '>>>': // unsigned right shift
13561
- return 8;
13754
+ return 9;
13562
13755
  case '++': // string concatenation
13563
- return 7;
13756
+ return 8;
13564
13757
  case '<': // less than
13565
13758
  case '<=': // less than or equal
13566
13759
  case '≤': // less than or equal
13567
13760
  case '>': // greater than
13568
13761
  case '>=': // greater than or equal
13569
13762
  case '≥': // greater than or equal
13570
- return 6;
13763
+ return 7;
13571
13764
  case '=': // equal
13572
13765
  case '!=': // not equal
13573
13766
  case '≠': // not equal
13574
- return 5;
13767
+ return 6;
13575
13768
  case '&': // bitwise AND
13576
13769
  case 'xor': // bitwise XOR
13577
13770
  case '|': // bitwise OR
13578
- return 4;
13771
+ return 5;
13579
13772
  case '&&': // logical AND
13580
13773
  case '||': // logical OR
13581
13774
  case '??': // nullish coalescing
13582
- return 3;
13775
+ return 4;
13776
+ // leave room for binaryFunctionalOperatorPrecedence = 3
13583
13777
  case '|>': // pipe
13584
- return 1;
13585
- // leave room for binaryFunctionalOperatorPrecedence = 2
13778
+ return 2;
13779
+ // leave room for conditionalOperatorPrecedence = 1
13586
13780
  /* v8 ignore next 2 */
13587
13781
  default:
13588
13782
  throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
@@ -13630,13 +13824,15 @@ function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeI
13630
13824
  case '||':
13631
13825
  case '??':
13632
13826
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes[operatorName], [left, right]]], sourceCodeInfo);
13633
- /* v8 ignore next 10 */
13827
+ /* v8 ignore next 11 */
13634
13828
  case '.':
13635
13829
  case ';':
13636
13830
  case ':=':
13637
13831
  case ',':
13638
13832
  case '->':
13639
13833
  case '...':
13834
+ case '?':
13835
+ case ':':
13640
13836
  throw new LitsError("Unknown binary operator: ".concat(operatorName), sourceCodeInfo);
13641
13837
  default:
13642
13838
  throw new LitsError("Unknown binary operator: ".concat(operatorName), sourceCodeInfo);
@@ -13752,6 +13948,19 @@ var Parser = /** @class */ (function () {
13752
13948
  }
13753
13949
  left = createNamedNormalExpressionNode(operatorSymbol, [left, right], operator[2]);
13754
13950
  }
13951
+ else if ((operator === null || operator === void 0 ? void 0 : operator[1]) === '?') {
13952
+ if (conditionalOperatorPrecedence <= precedence) {
13953
+ break;
13954
+ }
13955
+ this.advance();
13956
+ var trueNode = this.parseExpression();
13957
+ if (!isOperatorToken(this.peek(), ':')) {
13958
+ throw new LitsError('Expected :', this.peekSourceCodeInfo());
13959
+ }
13960
+ this.advance();
13961
+ var falseNode = this.parseExpression();
13962
+ left = withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.if, [left, trueNode, falseNode]]], left[2]);
13963
+ }
13755
13964
  else {
13756
13965
  break;
13757
13966
  }
@@ -14938,10 +15147,15 @@ function getVectorReductionNames(name) {
14938
15147
  var api = {
14939
15148
  collection: [
14940
15149
  'filter',
15150
+ 'filteri',
14941
15151
  'map',
15152
+ 'mapi',
14942
15153
  'reduce',
15154
+ 'reducei',
14943
15155
  'reduce-right',
15156
+ 'reducei-right',
14944
15157
  'reductions',
15158
+ 'reductionsi',
14945
15159
  'count',
14946
15160
  'get',
14947
15161
  'get-in',
@@ -14962,6 +15176,8 @@ var api = {
14962
15176
  'repeat',
14963
15177
  'flatten',
14964
15178
  'mapcat',
15179
+ 'moving-fn',
15180
+ 'running-fn',
14965
15181
  ],
14966
15182
  sequence: [
14967
15183
  'nth',
@@ -15101,7 +15317,6 @@ var api = {
15101
15317
  'even?',
15102
15318
  'odd?',
15103
15319
  'finite?',
15104
- 'nan?',
15105
15320
  'negative-infinity?',
15106
15321
  'positive-infinity?',
15107
15322
  'false?',
@@ -15438,7 +15653,7 @@ function getOperatorArgs(a, b) {
15438
15653
  }
15439
15654
 
15440
15655
  var arrayReference = {
15441
- range: {
15656
+ 'range': {
15442
15657
  title: 'range',
15443
15658
  category: 'Array',
15444
15659
  linkName: 'range',
@@ -15463,7 +15678,7 @@ var arrayReference = {
15463
15678
  "\nrange(\n 0.25, // start value\n 1, // end value (exclusive)\n 0.25, // step value\n)",
15464
15679
  ],
15465
15680
  },
15466
- repeat: {
15681
+ 'repeat': {
15467
15682
  title: 'repeat',
15468
15683
  category: 'Array',
15469
15684
  linkName: 'repeat',
@@ -15482,7 +15697,7 @@ var arrayReference = {
15482
15697
  '"Albert" repeat 5',
15483
15698
  ],
15484
15699
  },
15485
- flatten: {
15700
+ 'flatten': {
15486
15701
  title: 'flatten',
15487
15702
  category: 'Array',
15488
15703
  linkName: 'flatten',
@@ -15506,7 +15721,7 @@ var arrayReference = {
15506
15721
  ],
15507
15722
  noOperatorDocumentation: true,
15508
15723
  },
15509
- mapcat: {
15724
+ 'mapcat': {
15510
15725
  title: 'mapcat',
15511
15726
  category: 'Array',
15512
15727
  linkName: 'mapcat',
@@ -15531,6 +15746,60 @@ var arrayReference = {
15531
15746
  "\nmapcat(\n [[1, 2], [2, 2], [2, 3]],\n -> $ remove even?\n)",
15532
15747
  ],
15533
15748
  },
15749
+ 'moving-fn': {
15750
+ title: 'moving-fn',
15751
+ category: 'Array',
15752
+ linkName: 'moving-fn',
15753
+ returns: {
15754
+ type: 'array',
15755
+ },
15756
+ args: {
15757
+ arr: {
15758
+ type: 'array',
15759
+ },
15760
+ windowSize: {
15761
+ type: 'number',
15762
+ description: 'The size of the moving window.',
15763
+ },
15764
+ fn: {
15765
+ type: 'function',
15766
+ },
15767
+ },
15768
+ variants: [{
15769
+ argumentNames: ['arr', 'windowSize', 'fn'],
15770
+ }],
15771
+ description: 'Returns the result of applying $fn to each moving window of size $windowSize in $arr.',
15772
+ examples: [
15773
+ 'moving-fn([1, 2, 3], 2, vec:sum)',
15774
+ 'moving-fn([1, 2, 3], 1, vec:sum)',
15775
+ 'moving-fn([1, 2, 3], 3, vec:sum)',
15776
+ ],
15777
+ },
15778
+ 'running-fn': {
15779
+ title: 'running-fn',
15780
+ category: 'Array',
15781
+ linkName: 'running-fn',
15782
+ returns: {
15783
+ type: 'array',
15784
+ },
15785
+ args: {
15786
+ a: {
15787
+ type: 'array',
15788
+ },
15789
+ b: {
15790
+ type: 'function',
15791
+ },
15792
+ },
15793
+ variants: [{
15794
+ argumentNames: ['a', 'b'],
15795
+ }],
15796
+ description: 'Returns the result of applying $b to each element of $a.',
15797
+ examples: [
15798
+ 'running-fn([1, 2, 3], vec:sum)',
15799
+ 'running-fn([1, 2, 3], vec:max)',
15800
+ 'running-fn([1, 2, 3], vec:min)',
15801
+ ],
15802
+ },
15534
15803
  };
15535
15804
 
15536
15805
  var assertReference = {
@@ -16191,6 +16460,32 @@ var collectionReference = {
16191
16460
  "\nfilter(\n { a := 1, b := 2 },\n odd?\n)",
16192
16461
  ],
16193
16462
  },
16463
+ 'filteri': {
16464
+ title: 'filteri',
16465
+ category: 'Collection',
16466
+ linkName: 'filteri',
16467
+ returns: {
16468
+ type: 'collection',
16469
+ },
16470
+ args: {
16471
+ a: {
16472
+ type: 'collection',
16473
+ },
16474
+ b: {
16475
+ type: 'function',
16476
+ description: 'The function to call for each element in the collection. The function should take two arguments: the element itself and the index.',
16477
+ },
16478
+ },
16479
+ variants: [
16480
+ { argumentNames: ['a', 'b'] },
16481
+ ],
16482
+ description: 'Creates a new collection with all elements that pass the test implemented by $b. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.',
16483
+ examples: [
16484
+ 'filteri([1, 2, 3], (x, i) -> i % 2 = 0)',
16485
+ 'filteri([1, 2, 3], (x, i) -> x % 2 = 0)',
16486
+ 'filteri([1, 2, 3], (x, i) -> x + i > 3)',
16487
+ ],
16488
+ },
16194
16489
  'map': {
16195
16490
  title: 'map',
16196
16491
  category: 'Collection',
@@ -16219,6 +16514,34 @@ var collectionReference = {
16219
16514
  'map({ a := 1, b := 2 }, { a := 10, b := 20 }, +)',
16220
16515
  ],
16221
16516
  },
16517
+ 'mapi': {
16518
+ title: 'mapi',
16519
+ category: 'Collection',
16520
+ linkName: 'mapi',
16521
+ returns: {
16522
+ type: 'collection',
16523
+ },
16524
+ args: {
16525
+ a: {
16526
+ type: 'collection',
16527
+ },
16528
+ b: {
16529
+ type: 'function',
16530
+ description: 'The function to call for each element in the collection. The function should take two arguments: the element itself and the index.',
16531
+ },
16532
+ },
16533
+ variants: [
16534
+ { argumentNames: ['a', 'b'] },
16535
+ ],
16536
+ description: 'Creates a new collection populated with the results of calling $b on every element in $a. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.',
16537
+ examples: [
16538
+ 'mapi([1, 2, 3], (x, i) -> x + i)',
16539
+ 'mapi([1, 2, 3], (x, i) -> x * i)',
16540
+ 'mapi([1, 2, 3], (x, i) -> x - i)',
16541
+ 'mapi([1, 2, 3], (x, i) -> x / i)',
16542
+ 'mapi([1, 2, 3], (x, i) -> x % inc(i))',
16543
+ ],
16544
+ },
16222
16545
  'reduce': {
16223
16546
  title: 'reduce',
16224
16547
  category: 'Collection',
@@ -16275,12 +16598,73 @@ var collectionReference = {
16275
16598
  'reduce-right({ a := 1, b := 2 }, +, 0)',
16276
16599
  ],
16277
16600
  },
16601
+ 'reducei-right': {
16602
+ title: 'reducei-right',
16603
+ category: 'Collection',
16604
+ linkName: 'reducei-right',
16605
+ returns: {
16606
+ type: 'any',
16607
+ },
16608
+ args: {
16609
+ coll: {
16610
+ type: 'collection',
16611
+ },
16612
+ fun: {
16613
+ type: 'function',
16614
+ description: 'The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index.',
16615
+ },
16616
+ initial: {
16617
+ type: 'any',
16618
+ description: 'The initial value to use as the accumulator.',
16619
+ },
16620
+ },
16621
+ variants: [
16622
+ { argumentNames: ['coll', 'fun', 'initial'] },
16623
+ ],
16624
+ description: 'Runs $fun function on each element of the $coll (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.',
16625
+ examples: [
16626
+ 'reducei-right([1, 2, 3], (acc, x, i) -> acc + x + i, 0)',
16627
+ 'reducei-right("Albert", (acc, x, i) -> acc ++ x ++ i, "")',
16628
+ 'reducei-right({ a := 1, b := 2 }, -> $1 ++ $3, "")',
16629
+ ],
16630
+ },
16631
+ 'reducei': {
16632
+ title: 'reducei',
16633
+ category: 'Collection',
16634
+ linkName: 'reducei',
16635
+ returns: {
16636
+ type: 'any',
16637
+ },
16638
+ args: {
16639
+ coll: {
16640
+ type: 'collection',
16641
+ },
16642
+ fun: {
16643
+ type: 'function',
16644
+ description: 'The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index.',
16645
+ },
16646
+ initial: {
16647
+ type: 'any',
16648
+ description: 'The initial value to use as the accumulator.',
16649
+ },
16650
+ },
16651
+ variants: [
16652
+ { argumentNames: ['coll', 'fun', 'initial'] },
16653
+ ],
16654
+ description: 'Runs $fun function on each element of the $coll, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.',
16655
+ examples: [
16656
+ 'reducei([1, 2, 3], (acc, x, i) -> acc + x + i, 0)',
16657
+ 'reducei("Albert", (acc, x, i) -> acc ++ x ++ i, "")',
16658
+ 'reducei({ a := 1, b := 2 }, -> $1 ++ $3, "")',
16659
+ ],
16660
+ },
16278
16661
  'reductions': {
16279
16662
  title: 'reductions',
16280
16663
  category: 'Collection',
16281
16664
  linkName: 'reductions',
16282
16665
  returns: {
16283
16666
  type: 'any',
16667
+ array: true,
16284
16668
  },
16285
16669
  args: {
16286
16670
  fun: {
@@ -16305,6 +16689,37 @@ var collectionReference = {
16305
16689
  "\nreductions(\n [1, 2, 3, 4, 5, 6, 7, 8, 9],\n (result, value) -> result + if even?(value) then value else 0 end,\n 0\n)",
16306
16690
  ],
16307
16691
  },
16692
+ 'reductionsi': {
16693
+ title: 'reductionsi',
16694
+ category: 'Collection',
16695
+ linkName: 'reductionsi',
16696
+ returns: {
16697
+ type: 'any',
16698
+ array: true,
16699
+ },
16700
+ args: {
16701
+ coll: {
16702
+ type: 'collection',
16703
+ },
16704
+ fun: {
16705
+ type: 'function',
16706
+ description: 'The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index.',
16707
+ },
16708
+ initial: {
16709
+ type: 'any',
16710
+ description: 'The initial value to use as the accumulator.',
16711
+ },
16712
+ },
16713
+ variants: [
16714
+ { argumentNames: ['coll', 'fun', 'initial'] },
16715
+ ],
16716
+ description: 'Returns an array of the intermediate values of the reduction (see `reduce`) of $coll by $fun. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.',
16717
+ examples: [
16718
+ 'reductionsi([1, 2, 3], (acc, x, i) -> acc + x + i, 0)',
16719
+ 'reductionsi("Albert", (acc, x, i) -> acc ++ x ++ i, "")',
16720
+ 'reductionsi({ a := 1, b := 2 }, -> $1 ++ $3, "")',
16721
+ ],
16722
+ },
16308
16723
  'count': {
16309
16724
  title: 'count',
16310
16725
  category: 'Collection',
@@ -24769,30 +25184,6 @@ var predicateReference = {
24769
25184
  'finite?(1.0)',
24770
25185
  'finite?(1 / 0)',
24771
25186
  'finite?(-1 / 0)',
24772
- 'finite?(sqrt(-1))',
24773
- ],
24774
- },
24775
- 'nan?': {
24776
- title: 'nan?',
24777
- category: 'Predicate',
24778
- linkName: 'nan-question',
24779
- returns: {
24780
- type: 'boolean',
24781
- },
24782
- args: {
24783
- x: {
24784
- type: 'number',
24785
- },
24786
- },
24787
- variants: [
24788
- { argumentNames: ['x'] },
24789
- ],
24790
- description: 'Returns `true` if $x is NaN (! a number), otherwise `false`.',
24791
- examples: [
24792
- 'nan?(1.0)',
24793
- 'nan?(1 / 0)',
24794
- 'nan?(-1 / 0)',
24795
- 'nan?(sqrt(-1))',
24796
25187
  ],
24797
25188
  },
24798
25189
  'negative-infinity?': {
@@ -24815,7 +25206,6 @@ var predicateReference = {
24815
25206
  'negative-infinity?(1.0)',
24816
25207
  'negative-infinity?(1 / 0)',
24817
25208
  'negative-infinity?(-1 / 0)',
24818
- 'negative-infinity?(sqrt(-1))',
24819
25209
  ],
24820
25210
  },
24821
25211
  'positive-infinity?': {
@@ -24838,7 +25228,6 @@ var predicateReference = {
24838
25228
  'positive-infinity?(1.0)',
24839
25229
  'positive-infinity?(1 / 0)',
24840
25230
  'positive-infinity?(-1 / 0)',
24841
- 'positive-infinity?(sqrt(-1))',
24842
25231
  ],
24843
25232
  },
24844
25233
  'false?': {
@@ -30670,7 +31059,6 @@ var numberTheoryReference = __assign(__assign(__assign(__assign(__assign(__assig
30670
31059
  '12 nth:lcm 8',
30671
31060
  'nth:lcm(100, 25)',
30672
31061
  'nth:lcm(37, 1)',
30673
- 'nth:lcm(0, 0)',
30674
31062
  'nth:lcm(0, 5)',
30675
31063
  'nth:lcm(5, 0)',
30676
31064
  ],