@mojir/lits 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli/cli.js +220 -230
- package/dist/cli/reference/api.d.ts +5 -5
- package/dist/cli/reference/index.d.ts +8 -2
- package/dist/cli/src/tokenizer/operators.d.ts +2 -2
- package/dist/full.esm.js +1 -1
- package/dist/full.esm.js.map +1 -1
- package/dist/full.js +1 -1
- package/dist/full.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +1 -1
- package/dist/lits.iife.js.map +1 -1
- package/dist/modules/reference/api.d.ts +5 -5
- package/dist/modules/reference/index.d.ts +8 -2
- package/dist/modules/sequence.esm.js +1 -1
- package/dist/modules/sequence.esm.js.map +1 -1
- package/dist/modules/sequence.js +1 -1
- package/dist/modules/sequence.js.map +1 -1
- package/dist/modules/src/tokenizer/operators.d.ts +2 -2
- package/dist/reference/api.d.ts +5 -5
- package/dist/reference/index.d.ts +8 -2
- package/dist/src/tokenizer/operators.d.ts +2 -2
- package/dist/testFramework.esm.js +1 -1
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +1 -1
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1279,7 +1279,7 @@ Here's the complete precedence table, from highest to lowest:
|
|
|
1279
1279
|
| 9 | `<<` `>>` `>>>` | Bit shift operations | `8 >> 1 + 1` → `8 >> 2` → `2` |
|
|
1280
1280
|
| 8 | `++` | String concatenation | `"a" ++ "b" ++ "c"` → `"abc"` |
|
|
1281
1281
|
| 7 | `<` `<=` `>` `>=` | Comparison operators | `3 + 2 > 4` → `5 > 4` → `true` |
|
|
1282
|
-
| 6 | `==`
|
|
1282
|
+
| 6 | `==` `!=` | Equality operators | `2 * 3 == 6` → `6 == 6` → `true` |
|
|
1283
1283
|
| 5 | `&` `xor` `\|` | Bitwise operations | `4 \| 2 & 1` → `4 \| 0` → `4` |
|
|
1284
1284
|
| 4 | `&&` `\|\|` `??` | Logical operations | `true && false \|\| true` → `false \|\| true` → `true` |
|
|
1285
1285
|
| 3 | *function operators* | Binary functions used as operators | `5 max 3 + 2` → `5 max 5` → `5` |
|
package/dist/cli/cli.js
CHANGED
|
@@ -7,7 +7,7 @@ var readline = require('node:readline');
|
|
|
7
7
|
var os = require('node:os');
|
|
8
8
|
var process$1 = require('node:process');
|
|
9
9
|
|
|
10
|
-
var version = "2.3.
|
|
10
|
+
var version = "2.3.1";
|
|
11
11
|
|
|
12
12
|
function getCodeMarker(sourceCodeInfo) {
|
|
13
13
|
if (!sourceCodeInfo.position || !sourceCodeInfo.code)
|
|
@@ -2130,7 +2130,7 @@ For string $seq returns all but the first characters in $seq.`,
|
|
|
2130
2130
|
{ argumentNames: ['seq', 'start', 'stop'] },
|
|
2131
2131
|
],
|
|
2132
2132
|
description: 'Returns a copy of a portion of $seq from index $start (inclusive) to $stop (exclusive).',
|
|
2133
|
-
seeAlso: ['
|
|
2133
|
+
seeAlso: ['take', 'drop', 'sequence.splice', 'nth'],
|
|
2134
2134
|
examples: [
|
|
2135
2135
|
'[1, 2, 3, 4, 5] slice 2',
|
|
2136
2136
|
'slice([1, 2, 3, 4, 5], 2, 4)',
|
|
@@ -2272,6 +2272,191 @@ sort(
|
|
|
2272
2272
|
sort(
|
|
2273
2273
|
[3, 1, 2],
|
|
2274
2274
|
(a, b) -> cond case a > b then -1 case a < b then 1 case true then -1 end
|
|
2275
|
+
)`,
|
|
2276
|
+
],
|
|
2277
|
+
},
|
|
2278
|
+
},
|
|
2279
|
+
'take': {
|
|
2280
|
+
evaluate: ([input, n], sourceCodeInfo) => {
|
|
2281
|
+
assertNumber(n, sourceCodeInfo);
|
|
2282
|
+
assertSeq(input, sourceCodeInfo);
|
|
2283
|
+
const num = Math.max(Math.ceil(n), 0);
|
|
2284
|
+
return input.slice(0, num);
|
|
2285
|
+
},
|
|
2286
|
+
arity: toFixedArity(2),
|
|
2287
|
+
docs: {
|
|
2288
|
+
category: 'sequence',
|
|
2289
|
+
returns: { type: 'sequence' },
|
|
2290
|
+
args: {
|
|
2291
|
+
a: { type: 'sequence' },
|
|
2292
|
+
b: { type: 'integer' },
|
|
2293
|
+
n: { type: 'integer' },
|
|
2294
|
+
seq: { type: 'sequence' },
|
|
2295
|
+
},
|
|
2296
|
+
variants: [{ argumentNames: ['seq', 'n'] }],
|
|
2297
|
+
description: 'Constructs a new array/string with the $n first elements from $seq.',
|
|
2298
|
+
seeAlso: ['take-last', 'take-while', 'drop', 'slice', 'sequence.split-at'],
|
|
2299
|
+
examples: [
|
|
2300
|
+
'take([1, 2, 3, 4, 5], 3)',
|
|
2301
|
+
'[1, 2, 3, 4, 5] take 3',
|
|
2302
|
+
'take([1, 2, 3, 4, 5], 0)',
|
|
2303
|
+
'take("Albert", 2)',
|
|
2304
|
+
'take("Albert", 50)',
|
|
2305
|
+
],
|
|
2306
|
+
},
|
|
2307
|
+
},
|
|
2308
|
+
'take-last': {
|
|
2309
|
+
evaluate: ([array, n], sourceCodeInfo) => {
|
|
2310
|
+
assertSeq(array, sourceCodeInfo);
|
|
2311
|
+
assertNumber(n, sourceCodeInfo);
|
|
2312
|
+
const num = Math.max(Math.ceil(n), 0);
|
|
2313
|
+
const from = array.length - num;
|
|
2314
|
+
return array.slice(from);
|
|
2315
|
+
},
|
|
2316
|
+
arity: toFixedArity(2),
|
|
2317
|
+
docs: {
|
|
2318
|
+
category: 'sequence',
|
|
2319
|
+
returns: { type: 'sequence' },
|
|
2320
|
+
args: {
|
|
2321
|
+
a: { type: 'sequence' },
|
|
2322
|
+
b: { type: 'integer' },
|
|
2323
|
+
n: { type: 'integer' },
|
|
2324
|
+
seq: { type: 'sequence' },
|
|
2325
|
+
},
|
|
2326
|
+
variants: [{ argumentNames: ['seq', 'n'] }],
|
|
2327
|
+
description: 'Constructs a new array with the $n last elements from $seq.',
|
|
2328
|
+
seeAlso: ['take', 'drop-last'],
|
|
2329
|
+
examples: [
|
|
2330
|
+
'take-last([1, 2, 3, 4, 5], 3)',
|
|
2331
|
+
'[1, 2, 3, 4, 5] take-last 3',
|
|
2332
|
+
'take-last([1, 2, 3, 4, 5], 0)',
|
|
2333
|
+
],
|
|
2334
|
+
},
|
|
2335
|
+
},
|
|
2336
|
+
'drop': {
|
|
2337
|
+
evaluate: ([input, n], sourceCodeInfo) => {
|
|
2338
|
+
assertNumber(n, sourceCodeInfo);
|
|
2339
|
+
const num = Math.max(Math.ceil(n), 0);
|
|
2340
|
+
assertSeq(input, sourceCodeInfo);
|
|
2341
|
+
return input.slice(num);
|
|
2342
|
+
},
|
|
2343
|
+
arity: toFixedArity(2),
|
|
2344
|
+
docs: {
|
|
2345
|
+
category: 'sequence',
|
|
2346
|
+
returns: { type: 'sequence' },
|
|
2347
|
+
args: {
|
|
2348
|
+
a: { type: 'sequence' },
|
|
2349
|
+
b: { type: 'integer' },
|
|
2350
|
+
seq: { type: 'sequence' },
|
|
2351
|
+
n: { type: 'integer' },
|
|
2352
|
+
},
|
|
2353
|
+
variants: [{ argumentNames: ['seq', 'n'] }],
|
|
2354
|
+
description: 'Constructs a new array/string with the $n first elements dropped from $seq.',
|
|
2355
|
+
seeAlso: ['drop-last', 'drop-while', 'take', 'slice', 'sequence.split-at'],
|
|
2356
|
+
examples: [
|
|
2357
|
+
'drop([1, 2, 3, 4, 5], 3)',
|
|
2358
|
+
'[1, 2, 3, 4, 5] drop 0',
|
|
2359
|
+
'drop("Albert", 2)',
|
|
2360
|
+
'drop("Albert", 50)',
|
|
2361
|
+
],
|
|
2362
|
+
},
|
|
2363
|
+
},
|
|
2364
|
+
'drop-last': {
|
|
2365
|
+
evaluate: ([array, n], sourceCodeInfo) => {
|
|
2366
|
+
assertSeq(array, sourceCodeInfo);
|
|
2367
|
+
assertNumber(n, sourceCodeInfo);
|
|
2368
|
+
const num = Math.max(Math.ceil(n), 0);
|
|
2369
|
+
const from = array.length - num;
|
|
2370
|
+
return array.slice(0, from);
|
|
2371
|
+
},
|
|
2372
|
+
arity: toFixedArity(2),
|
|
2373
|
+
docs: {
|
|
2374
|
+
category: 'sequence',
|
|
2375
|
+
returns: { type: 'sequence' },
|
|
2376
|
+
args: {
|
|
2377
|
+
a: { type: 'sequence' },
|
|
2378
|
+
b: { type: 'integer' },
|
|
2379
|
+
seq: { type: 'sequence' },
|
|
2380
|
+
n: { type: 'integer' },
|
|
2381
|
+
},
|
|
2382
|
+
variants: [{ argumentNames: ['seq', 'n'] }],
|
|
2383
|
+
description: 'Constructs a new array with the $n last elements dropped from $seq.',
|
|
2384
|
+
seeAlso: ['drop', 'take-last'],
|
|
2385
|
+
examples: [
|
|
2386
|
+
'drop-last([1, 2, 3, 4, 5], 3)',
|
|
2387
|
+
'[1, 2, 3, 4, 5] drop-last 3',
|
|
2388
|
+
'drop-last([1, 2, 3, 4, 5], 0)',
|
|
2389
|
+
],
|
|
2390
|
+
},
|
|
2391
|
+
},
|
|
2392
|
+
'take-while': {
|
|
2393
|
+
evaluate: ([seq, fn], sourceCodeInfo, contextStack, { executeFunction }) => {
|
|
2394
|
+
assertSeq(seq, sourceCodeInfo);
|
|
2395
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
2396
|
+
const arr = typeof seq === 'string' ? seq.split('') : Array.from(seq);
|
|
2397
|
+
// Find the first index where the predicate is false
|
|
2398
|
+
return chain(findIndexSequential(arr, elem => chain(executeFunction(fn, [elem], contextStack, sourceCodeInfo), result => !result)), (index) => {
|
|
2399
|
+
const taken = index === -1 ? arr : arr.slice(0, index);
|
|
2400
|
+
return typeof seq === 'string' ? taken.join('') : taken;
|
|
2401
|
+
});
|
|
2402
|
+
},
|
|
2403
|
+
arity: toFixedArity(2),
|
|
2404
|
+
docs: {
|
|
2405
|
+
category: 'sequence',
|
|
2406
|
+
returns: { type: 'sequence' },
|
|
2407
|
+
args: {
|
|
2408
|
+
a: { type: 'sequence' },
|
|
2409
|
+
b: { type: 'function' },
|
|
2410
|
+
seq: { type: 'sequence' },
|
|
2411
|
+
fun: { type: 'function' },
|
|
2412
|
+
},
|
|
2413
|
+
variants: [{ argumentNames: ['seq', 'fun'] }],
|
|
2414
|
+
description: 'Returns the members of $seq in order, stopping before the first one for which `predicate` returns a falsy value.',
|
|
2415
|
+
seeAlso: ['take', 'drop-while', 'sequence.split-with'],
|
|
2416
|
+
examples: [
|
|
2417
|
+
`take-while(
|
|
2418
|
+
[1, 2, 3, 2, 1],
|
|
2419
|
+
-> $ < 3
|
|
2420
|
+
)`,
|
|
2421
|
+
`take-while(
|
|
2422
|
+
[1, 2, 3, 2, 1],
|
|
2423
|
+
-> $ > 3
|
|
2424
|
+
)`,
|
|
2425
|
+
],
|
|
2426
|
+
},
|
|
2427
|
+
},
|
|
2428
|
+
'drop-while': {
|
|
2429
|
+
evaluate: ([seq, fn], sourceCodeInfo, contextStack, { executeFunction }) => {
|
|
2430
|
+
assertSeq(seq, sourceCodeInfo);
|
|
2431
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
2432
|
+
const arr = Array.isArray(seq) ? seq : seq.split('');
|
|
2433
|
+
return chain(findIndexSequential(arr, elem => chain(executeFunction(fn, [elem], contextStack, sourceCodeInfo), result => !result)), (from) => {
|
|
2434
|
+
if (from === -1)
|
|
2435
|
+
return typeof seq === 'string' ? '' : [];
|
|
2436
|
+
return typeof seq === 'string' ? arr.slice(from).join('') : seq.slice(from);
|
|
2437
|
+
});
|
|
2438
|
+
},
|
|
2439
|
+
arity: toFixedArity(2),
|
|
2440
|
+
docs: {
|
|
2441
|
+
category: 'sequence',
|
|
2442
|
+
returns: { type: 'sequence' },
|
|
2443
|
+
args: {
|
|
2444
|
+
a: { type: 'sequence' },
|
|
2445
|
+
b: { type: 'function' },
|
|
2446
|
+
seq: { type: 'sequence' },
|
|
2447
|
+
fun: { type: 'function' },
|
|
2448
|
+
},
|
|
2449
|
+
variants: [{ argumentNames: ['seq', 'fun'] }],
|
|
2450
|
+
description: 'Returns the members of $seq in order, skipping the fist elements for witch the `predicate` returns a truethy value.',
|
|
2451
|
+
seeAlso: ['drop', 'take-while', 'sequence.split-with'],
|
|
2452
|
+
examples: [
|
|
2453
|
+
`drop-while(
|
|
2454
|
+
[1, 2, 3, 2, 1],
|
|
2455
|
+
-> $ < 3
|
|
2456
|
+
)`,
|
|
2457
|
+
`drop-while(
|
|
2458
|
+
[1, 2, 3, 2, 1],
|
|
2459
|
+
-> $ > 3
|
|
2275
2460
|
)`,
|
|
2276
2461
|
],
|
|
2277
2462
|
},
|
|
@@ -3208,7 +3393,7 @@ const miscNormalExpression = {
|
|
|
3208
3393
|
{ argumentNames: ['x', 'ys'] },
|
|
3209
3394
|
],
|
|
3210
3395
|
description: 'Returns `true` if all `values` are structaul equal to each other, otherwise result is `false`.',
|
|
3211
|
-
seeAlso: ['
|
|
3396
|
+
seeAlso: ['!=', 'identical?'],
|
|
3212
3397
|
examples: [
|
|
3213
3398
|
'1 == 1',
|
|
3214
3399
|
'[1, 2] == [1, 2]',
|
|
@@ -3230,7 +3415,7 @@ const miscNormalExpression = {
|
|
|
3230
3415
|
],
|
|
3231
3416
|
},
|
|
3232
3417
|
},
|
|
3233
|
-
'
|
|
3418
|
+
'!=': {
|
|
3234
3419
|
evaluate: (params, sourceCodeInfo) => {
|
|
3235
3420
|
return !isEqual(params, sourceCodeInfo);
|
|
3236
3421
|
},
|
|
@@ -3248,15 +3433,15 @@ const miscNormalExpression = {
|
|
|
3248
3433
|
{ argumentNames: ['x'] },
|
|
3249
3434
|
{ argumentNames: ['x', 'ys'] },
|
|
3250
3435
|
],
|
|
3251
|
-
description: 'Returns `true` if all `values` are not equal to each other, otherwise result is `false`. `(
|
|
3436
|
+
description: 'Returns `true` if all `values` are not equal to each other, otherwise result is `false`. `(!= a b c)` is same as `(not (== a b c))`.',
|
|
3252
3437
|
seeAlso: ['==', 'identical?'],
|
|
3253
3438
|
examples: [
|
|
3254
|
-
'1
|
|
3255
|
-
'3
|
|
3256
|
-
'
|
|
3257
|
-
'
|
|
3258
|
-
'
|
|
3259
|
-
'
|
|
3439
|
+
'1 != 2',
|
|
3440
|
+
'3 != 3',
|
|
3441
|
+
'!=(3)',
|
|
3442
|
+
'!=(3, 3, 2)',
|
|
3443
|
+
'!=("3", "2", "1", "0",)',
|
|
3444
|
+
'!=(0, -0)',
|
|
3260
3445
|
],
|
|
3261
3446
|
},
|
|
3262
3447
|
},
|
|
@@ -3274,7 +3459,7 @@ const miscNormalExpression = {
|
|
|
3274
3459
|
},
|
|
3275
3460
|
variants: [{ argumentNames: ['a', 'b'] }],
|
|
3276
3461
|
description: 'Returns true if $a and $b are referential equal.',
|
|
3277
|
-
seeAlso: ['==', '
|
|
3462
|
+
seeAlso: ['==', '!='],
|
|
3278
3463
|
examples: [
|
|
3279
3464
|
'identical?({ a: 10, b: 20 }, { b: 20, a: 10 })',
|
|
3280
3465
|
'identical?([1, true, null], [1, true, null])',
|
|
@@ -3425,7 +3610,7 @@ const miscNormalExpression = {
|
|
|
3425
3610
|
],
|
|
3426
3611
|
},
|
|
3427
3612
|
},
|
|
3428
|
-
'
|
|
3613
|
+
'not': {
|
|
3429
3614
|
evaluate: ([first]) => !first,
|
|
3430
3615
|
arity: toFixedArity(1),
|
|
3431
3616
|
docs: {
|
|
@@ -3436,13 +3621,13 @@ const miscNormalExpression = {
|
|
|
3436
3621
|
description: 'Computes logical negation. Note that any other $x than `false`, `0`, `null` and `\'\'` is truthy.',
|
|
3437
3622
|
seeAlso: ['boolean'],
|
|
3438
3623
|
examples: [
|
|
3439
|
-
'
|
|
3440
|
-
'
|
|
3441
|
-
'
|
|
3442
|
-
'
|
|
3443
|
-
'
|
|
3444
|
-
'
|
|
3445
|
-
'
|
|
3624
|
+
'not(3)',
|
|
3625
|
+
'not(true)',
|
|
3626
|
+
'not("A string")',
|
|
3627
|
+
'not(0)',
|
|
3628
|
+
'not(false)',
|
|
3629
|
+
'not(null)',
|
|
3630
|
+
'not("")',
|
|
3446
3631
|
],
|
|
3447
3632
|
},
|
|
3448
3633
|
},
|
|
@@ -3523,7 +3708,7 @@ const miscNormalExpression = {
|
|
|
3523
3708
|
args: { x: { type: 'any' } },
|
|
3524
3709
|
variants: [{ argumentNames: ['x'] }],
|
|
3525
3710
|
description: 'Coerces $x to boolean.',
|
|
3526
|
-
seeAlso: ['
|
|
3711
|
+
seeAlso: ['not', 'boolean?', 'true?', 'false?'],
|
|
3527
3712
|
examples: [
|
|
3528
3713
|
'boolean(0)',
|
|
3529
3714
|
'boolean(1)',
|
|
@@ -6269,7 +6454,7 @@ const docs$4 = {
|
|
|
6269
6454
|
`
|
|
6270
6455
|
let foo = (n) -> do
|
|
6271
6456
|
write!(n);
|
|
6272
|
-
if
|
|
6457
|
+
if not(zero?(n)) then
|
|
6273
6458
|
recur(n - 1)
|
|
6274
6459
|
end
|
|
6275
6460
|
end;
|
|
@@ -6277,14 +6462,14 @@ foo(3)`,
|
|
|
6277
6462
|
`
|
|
6278
6463
|
(n -> do
|
|
6279
6464
|
write!(n);
|
|
6280
|
-
if
|
|
6465
|
+
if not(zero?(n)) then
|
|
6281
6466
|
recur(n - 1)
|
|
6282
6467
|
end
|
|
6283
6468
|
end)(3)`,
|
|
6284
6469
|
`
|
|
6285
6470
|
loop (n = 3) -> do
|
|
6286
6471
|
write!(n);
|
|
6287
|
-
if
|
|
6472
|
+
if not(zero?(n)) then
|
|
6288
6473
|
recur(n - 1)
|
|
6289
6474
|
end
|
|
6290
6475
|
end`,
|
|
@@ -7228,7 +7413,7 @@ const binaryOperators = [
|
|
|
7228
7413
|
'≥', // greater than or equal
|
|
7229
7414
|
'==', // equal
|
|
7230
7415
|
'!=', // not equal
|
|
7231
|
-
'
|
|
7416
|
+
'!=', // not equal
|
|
7232
7417
|
'&', // bitwise AND
|
|
7233
7418
|
'xor', // bitwise XOR
|
|
7234
7419
|
'|', // bitwise OR
|
|
@@ -8138,7 +8323,6 @@ function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeI
|
|
|
8138
8323
|
case '≥':
|
|
8139
8324
|
case '==':
|
|
8140
8325
|
case '!=':
|
|
8141
|
-
case '≠':
|
|
8142
8326
|
case '&':
|
|
8143
8327
|
case 'xor':
|
|
8144
8328
|
case '|':
|
|
@@ -9062,7 +9246,6 @@ function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
|
9062
9246
|
return 7;
|
|
9063
9247
|
case '==': // equal
|
|
9064
9248
|
case '!=': // not equal
|
|
9065
|
-
case '≠': // not equal
|
|
9066
9249
|
return 6;
|
|
9067
9250
|
case '&': // bitwise AND
|
|
9068
9251
|
case 'xor': // bitwise XOR
|
|
@@ -31293,199 +31476,6 @@ su.position(
|
|
|
31293
31476
|
],
|
|
31294
31477
|
},
|
|
31295
31478
|
},
|
|
31296
|
-
'take': {
|
|
31297
|
-
evaluate: ([input, n], sourceCodeInfo) => {
|
|
31298
|
-
assertNumber(n, sourceCodeInfo);
|
|
31299
|
-
assertSeq(input, sourceCodeInfo);
|
|
31300
|
-
const num = Math.max(Math.ceil(n), 0);
|
|
31301
|
-
return input.slice(0, num);
|
|
31302
|
-
},
|
|
31303
|
-
arity: toFixedArity(2),
|
|
31304
|
-
docs: {
|
|
31305
|
-
category: 'sequence',
|
|
31306
|
-
returns: { type: 'sequence' },
|
|
31307
|
-
args: {
|
|
31308
|
-
a: { type: 'sequence' },
|
|
31309
|
-
b: { type: 'integer' },
|
|
31310
|
-
n: { type: 'integer' },
|
|
31311
|
-
seq: { type: 'sequence' },
|
|
31312
|
-
},
|
|
31313
|
-
variants: [{ argumentNames: ['seq', 'n'] }],
|
|
31314
|
-
description: 'Constructs a new array/string with the $n first elements from $seq.',
|
|
31315
|
-
seeAlso: ['sequence.take-last', 'sequence.take-while', 'sequence.drop', 'slice', 'sequence.split-at'],
|
|
31316
|
-
examples: [
|
|
31317
|
-
'let su = import("sequence"); su.take([1, 2, 3, 4, 5], 3)',
|
|
31318
|
-
'let su = import("sequence"); su.take([1, 2, 3, 4, 5], 3)',
|
|
31319
|
-
'let su = import("sequence"); su.take([1, 2, 3, 4, 5], 0)',
|
|
31320
|
-
'let su = import("sequence"); su.take("Albert", 2)',
|
|
31321
|
-
'let su = import("sequence"); su.take("Albert", 50)',
|
|
31322
|
-
],
|
|
31323
|
-
},
|
|
31324
|
-
},
|
|
31325
|
-
'take-last': {
|
|
31326
|
-
evaluate: ([array, n], sourceCodeInfo) => {
|
|
31327
|
-
assertSeq(array, sourceCodeInfo);
|
|
31328
|
-
assertNumber(n, sourceCodeInfo);
|
|
31329
|
-
const num = Math.max(Math.ceil(n), 0);
|
|
31330
|
-
const from = array.length - num;
|
|
31331
|
-
return array.slice(from);
|
|
31332
|
-
},
|
|
31333
|
-
arity: toFixedArity(2),
|
|
31334
|
-
docs: {
|
|
31335
|
-
category: 'sequence',
|
|
31336
|
-
returns: { type: 'sequence' },
|
|
31337
|
-
args: {
|
|
31338
|
-
a: { type: 'sequence' },
|
|
31339
|
-
b: { type: 'integer' },
|
|
31340
|
-
n: { type: 'integer' },
|
|
31341
|
-
seq: { type: 'sequence' },
|
|
31342
|
-
},
|
|
31343
|
-
variants: [{ argumentNames: ['n', 'seq'] }],
|
|
31344
|
-
description: 'Constructs a new array with the $n last elements from $seq.',
|
|
31345
|
-
seeAlso: ['sequence.take', 'sequence.drop-last'],
|
|
31346
|
-
examples: [
|
|
31347
|
-
'let su = import("sequence"); su.take-last([1, 2, 3, 4, 5], 3)',
|
|
31348
|
-
'let su = import("sequence"); su.take-last([1, 2, 3, 4, 5], 3)',
|
|
31349
|
-
'let su = import("sequence"); su.take-last([1, 2, 3, 4, 5], 0)',
|
|
31350
|
-
],
|
|
31351
|
-
},
|
|
31352
|
-
},
|
|
31353
|
-
'take-while': {
|
|
31354
|
-
evaluate: ([seq, fn], sourceCodeInfo, contextStack, { executeFunction }) => {
|
|
31355
|
-
assertSeq(seq, sourceCodeInfo);
|
|
31356
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
31357
|
-
const arr = typeof seq === 'string' ? seq.split('') : Array.from(seq);
|
|
31358
|
-
// Find the first index where the predicate is false
|
|
31359
|
-
return chain(findIndexSequential(arr, elem => chain(executeFunction(fn, [elem], contextStack, sourceCodeInfo), result => !result)), (index) => {
|
|
31360
|
-
const taken = index === -1 ? arr : arr.slice(0, index);
|
|
31361
|
-
return typeof seq === 'string' ? taken.join('') : taken;
|
|
31362
|
-
});
|
|
31363
|
-
},
|
|
31364
|
-
arity: toFixedArity(2),
|
|
31365
|
-
docs: {
|
|
31366
|
-
category: 'sequence',
|
|
31367
|
-
returns: { type: 'sequence' },
|
|
31368
|
-
args: {
|
|
31369
|
-
a: { type: 'sequence' },
|
|
31370
|
-
b: { type: 'function' },
|
|
31371
|
-
seq: { type: 'sequence' },
|
|
31372
|
-
fun: { type: 'function' },
|
|
31373
|
-
},
|
|
31374
|
-
variants: [{ argumentNames: ['seq', 'fun'] }],
|
|
31375
|
-
description: 'Returns the members of $seq in order, stopping before the first one for which `predicate` returns a falsy value.',
|
|
31376
|
-
seeAlso: ['sequence.take', 'sequence.drop-while', 'sequence.split-with'],
|
|
31377
|
-
examples: [
|
|
31378
|
-
`
|
|
31379
|
-
let su = import("sequence");
|
|
31380
|
-
su.take-while(
|
|
31381
|
-
[1, 2, 3, 2, 1],
|
|
31382
|
-
-> $ < 3
|
|
31383
|
-
)`,
|
|
31384
|
-
`
|
|
31385
|
-
let su = import("sequence");
|
|
31386
|
-
su.take-while(
|
|
31387
|
-
[1, 2, 3, 2, 1],
|
|
31388
|
-
-> $ > 3
|
|
31389
|
-
)`,
|
|
31390
|
-
],
|
|
31391
|
-
},
|
|
31392
|
-
},
|
|
31393
|
-
'drop': {
|
|
31394
|
-
evaluate: ([input, n], sourceCodeInfo) => {
|
|
31395
|
-
assertNumber(n, sourceCodeInfo);
|
|
31396
|
-
const num = Math.max(Math.ceil(n), 0);
|
|
31397
|
-
assertSeq(input, sourceCodeInfo);
|
|
31398
|
-
return input.slice(num);
|
|
31399
|
-
},
|
|
31400
|
-
arity: toFixedArity(2),
|
|
31401
|
-
docs: {
|
|
31402
|
-
category: 'sequence',
|
|
31403
|
-
returns: { type: 'sequence' },
|
|
31404
|
-
args: {
|
|
31405
|
-
a: { type: 'sequence' },
|
|
31406
|
-
b: { type: 'integer' },
|
|
31407
|
-
seq: { type: 'sequence' },
|
|
31408
|
-
n: { type: 'integer' },
|
|
31409
|
-
},
|
|
31410
|
-
variants: [{ argumentNames: ['seq', 'n'] }],
|
|
31411
|
-
description: 'Constructs a new array/string with the $n first elements dropped from $seq.',
|
|
31412
|
-
seeAlso: ['sequence.drop-last', 'sequence.drop-while', 'sequence.take', 'slice', 'sequence.split-at'],
|
|
31413
|
-
examples: [
|
|
31414
|
-
'let su = import("sequence"); su.drop([1, 2, 3, 4, 5], 3)',
|
|
31415
|
-
'let su = import("sequence"); su.drop([1, 2, 3, 4, 5], 0)',
|
|
31416
|
-
'let su = import("sequence"); su.drop("Albert", 2)',
|
|
31417
|
-
'let su = import("sequence"); su.drop("Albert", 50)',
|
|
31418
|
-
],
|
|
31419
|
-
},
|
|
31420
|
-
},
|
|
31421
|
-
'drop-last': {
|
|
31422
|
-
evaluate: ([array, n], sourceCodeInfo) => {
|
|
31423
|
-
assertSeq(array, sourceCodeInfo);
|
|
31424
|
-
assertNumber(n, sourceCodeInfo);
|
|
31425
|
-
const num = Math.max(Math.ceil(n), 0);
|
|
31426
|
-
const from = array.length - num;
|
|
31427
|
-
return array.slice(0, from);
|
|
31428
|
-
},
|
|
31429
|
-
arity: toFixedArity(2),
|
|
31430
|
-
docs: {
|
|
31431
|
-
category: 'sequence',
|
|
31432
|
-
returns: { type: 'sequence' },
|
|
31433
|
-
args: {
|
|
31434
|
-
a: { type: 'sequence' },
|
|
31435
|
-
b: { type: 'integer' },
|
|
31436
|
-
seq: { type: 'sequence' },
|
|
31437
|
-
n: { type: 'integer' },
|
|
31438
|
-
},
|
|
31439
|
-
variants: [{ argumentNames: ['seq', 'n'] }],
|
|
31440
|
-
description: 'Constructs a new array with the $n last elements dropped from $seq.',
|
|
31441
|
-
seeAlso: ['sequence.drop', 'sequence.take-last'],
|
|
31442
|
-
examples: [
|
|
31443
|
-
'let su = import("sequence"); su.drop-last([1, 2, 3, 4, 5], 3)',
|
|
31444
|
-
'let su = import("sequence"); su.drop-last([1, 2, 3, 4, 5], 3)',
|
|
31445
|
-
'let su = import("sequence"); su.drop-last([1, 2, 3, 4, 5], 0)',
|
|
31446
|
-
],
|
|
31447
|
-
},
|
|
31448
|
-
},
|
|
31449
|
-
'drop-while': {
|
|
31450
|
-
evaluate: ([seq, fn], sourceCodeInfo, contextStack, { executeFunction }) => {
|
|
31451
|
-
assertSeq(seq, sourceCodeInfo);
|
|
31452
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
31453
|
-
const arr = Array.isArray(seq) ? seq : seq.split('');
|
|
31454
|
-
return chain(findIndexSequential(arr, elem => chain(executeFunction(fn, [elem], contextStack, sourceCodeInfo), result => !result)), (from) => {
|
|
31455
|
-
if (from === -1)
|
|
31456
|
-
return typeof seq === 'string' ? '' : [];
|
|
31457
|
-
return typeof seq === 'string' ? arr.slice(from).join('') : seq.slice(from);
|
|
31458
|
-
});
|
|
31459
|
-
},
|
|
31460
|
-
arity: toFixedArity(2),
|
|
31461
|
-
docs: {
|
|
31462
|
-
category: 'sequence',
|
|
31463
|
-
returns: { type: 'sequence' },
|
|
31464
|
-
args: {
|
|
31465
|
-
a: { type: 'sequence' },
|
|
31466
|
-
b: { type: 'function' },
|
|
31467
|
-
seq: { type: 'sequence' },
|
|
31468
|
-
fun: { type: 'function' },
|
|
31469
|
-
},
|
|
31470
|
-
variants: [{ argumentNames: ['seq', 'fun'] }],
|
|
31471
|
-
description: 'Returns the members of $seq in order, skipping the fist elements for witch the `predicate` returns a truethy value.',
|
|
31472
|
-
seeAlso: ['sequence.drop', 'sequence.take-while', 'sequence.split-with'],
|
|
31473
|
-
examples: [
|
|
31474
|
-
`
|
|
31475
|
-
let su = import("sequence");
|
|
31476
|
-
su.drop-while(
|
|
31477
|
-
[1, 2, 3, 2, 1],
|
|
31478
|
-
-> $ < 3
|
|
31479
|
-
)`,
|
|
31480
|
-
`
|
|
31481
|
-
let su = import("sequence");
|
|
31482
|
-
su.drop-while(
|
|
31483
|
-
[1, 2, 3, 2, 1],
|
|
31484
|
-
-> $ > 3
|
|
31485
|
-
)`,
|
|
31486
|
-
],
|
|
31487
|
-
},
|
|
31488
|
-
},
|
|
31489
31479
|
'unshift': {
|
|
31490
31480
|
evaluate: ([seq, ...values], sourceCodeInfo) => {
|
|
31491
31481
|
assertSeq(seq, sourceCodeInfo);
|
|
@@ -31634,7 +31624,7 @@ l`,
|
|
|
31634
31624
|
},
|
|
31635
31625
|
variants: [{ argumentNames: ['seq', 'n'] }],
|
|
31636
31626
|
description: 'Returns a pair of sequence `[take(pos input), drop(pos input)]`.',
|
|
31637
|
-
seeAlso: ['sequence.split-with', '
|
|
31627
|
+
seeAlso: ['sequence.split-with', 'take', 'drop'],
|
|
31638
31628
|
examples: [
|
|
31639
31629
|
'let su = import("sequence"); su.split-at([1, 2, 3, 4, 5], 2)',
|
|
31640
31630
|
'let su = import("sequence"); su.split-at("Albert", -2)',
|
|
@@ -31667,7 +31657,7 @@ l`,
|
|
|
31667
31657
|
},
|
|
31668
31658
|
variants: [{ argumentNames: ['seq', 'fun'] }],
|
|
31669
31659
|
description: 'Returns a pair of sequences `[take-while(input, fun), drop-while(input, fun)]`.',
|
|
31670
|
-
seeAlso: ['sequence.split-at', '
|
|
31660
|
+
seeAlso: ['sequence.split-at', 'take-while', 'drop-while'],
|
|
31671
31661
|
examples: [
|
|
31672
31662
|
'let su = import("sequence"); su.split-with([1, 2, 3, 4, 5], odd?)',
|
|
31673
31663
|
'let su = import("sequence"); su.split-with([1, 2, 3, 4, 5], -> $ > 3)',
|
|
@@ -33089,6 +33079,12 @@ const api = {
|
|
|
33089
33079
|
'next',
|
|
33090
33080
|
'sort',
|
|
33091
33081
|
'slice',
|
|
33082
|
+
'take',
|
|
33083
|
+
'take-last',
|
|
33084
|
+
'drop',
|
|
33085
|
+
'drop-last',
|
|
33086
|
+
'take-while',
|
|
33087
|
+
'drop-while',
|
|
33092
33088
|
],
|
|
33093
33089
|
sequenceUtils: [
|
|
33094
33090
|
'sequence.position',
|
|
@@ -33097,12 +33093,6 @@ const api = {
|
|
|
33097
33093
|
'sequence.unshift',
|
|
33098
33094
|
'sequence.splice',
|
|
33099
33095
|
'sequence.sort-by',
|
|
33100
|
-
'sequence.take',
|
|
33101
|
-
'sequence.take-last',
|
|
33102
|
-
'sequence.take-while',
|
|
33103
|
-
'sequence.drop',
|
|
33104
|
-
'sequence.drop-last',
|
|
33105
|
-
'sequence.drop-while',
|
|
33106
33096
|
'sequence.distinct',
|
|
33107
33097
|
'sequence.remove',
|
|
33108
33098
|
'sequence.remove-at',
|
|
@@ -33178,13 +33168,13 @@ const api = {
|
|
|
33178
33168
|
'arity',
|
|
33179
33169
|
],
|
|
33180
33170
|
misc: [
|
|
33181
|
-
'
|
|
33171
|
+
'!=',
|
|
33182
33172
|
'==',
|
|
33183
33173
|
'<',
|
|
33184
33174
|
'>',
|
|
33185
33175
|
'<=',
|
|
33186
33176
|
'>=',
|
|
33187
|
-
'
|
|
33177
|
+
'not',
|
|
33188
33178
|
'write!',
|
|
33189
33179
|
'iso-date->epoch',
|
|
33190
33180
|
'epoch->iso-date',
|