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