@eslint-react/var 5.24.0 → 5.24.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/dist/index.js +367 -67
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ import { P, isMatching } from "ts-pattern";
|
|
|
37
37
|
* (n) => n + 2,
|
|
38
38
|
* (n) => n * 3
|
|
39
39
|
* )
|
|
40
|
-
*
|
|
40
|
+
* result // => 21
|
|
41
41
|
* ```
|
|
42
42
|
*
|
|
43
43
|
* @category combinators
|
|
@@ -94,16 +94,6 @@ const Class = (function() {
|
|
|
94
94
|
return PipeableBase;
|
|
95
95
|
})();
|
|
96
96
|
/**
|
|
97
|
-
* Provides small helpers for defining and reusing TypeScript functions.
|
|
98
|
-
*
|
|
99
|
-
* The main helpers are `pipe` and `flow` for left-to-right composition and
|
|
100
|
-
* `dual` for APIs that support both direct and pipe-friendly call styles. The
|
|
101
|
-
* module also contains small identity, constant, tuple, type-level, and
|
|
102
|
-
* memoization helpers used across the library.
|
|
103
|
-
*
|
|
104
|
-
* @since 2.0.0
|
|
105
|
-
*/
|
|
106
|
-
/**
|
|
107
97
|
* Creates a function that can be called in data-first style or data-last
|
|
108
98
|
* (`pipe`-friendly) style.
|
|
109
99
|
*
|
|
@@ -128,8 +118,8 @@ const Class = (function() {
|
|
|
128
118
|
* (self: number, that: number) => number
|
|
129
119
|
* >(2, (self, that) => self + that)
|
|
130
120
|
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
121
|
+
* sum(2, 3) // => 5
|
|
122
|
+
* pipe(2, sum(3)) // => 5
|
|
133
123
|
* ```
|
|
134
124
|
*
|
|
135
125
|
* **Example** (Defining overloads with call signatures)
|
|
@@ -142,8 +132,8 @@ const Class = (function() {
|
|
|
142
132
|
* (self: number, that: number): number
|
|
143
133
|
* } = Function.dual(2, (self: number, that: number): number => self + that)
|
|
144
134
|
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
135
|
+
* sum(2, 3) // => 5
|
|
136
|
+
* pipe(2, sum(3)) // => 5
|
|
147
137
|
* ```
|
|
148
138
|
*
|
|
149
139
|
* **Example** (Selecting data-first or data-last style with a predicate)
|
|
@@ -159,8 +149,8 @@ const Class = (function() {
|
|
|
159
149
|
* (self, that) => self + that
|
|
160
150
|
* )
|
|
161
151
|
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
152
|
+
* sum(2, 3) // => 5
|
|
153
|
+
* pipe(2, sum(3)) // => 5
|
|
164
154
|
* ```
|
|
165
155
|
*
|
|
166
156
|
* @category combinators
|
|
@@ -205,9 +195,8 @@ const dual = function(arity, body) {
|
|
|
205
195
|
*
|
|
206
196
|
* ```ts
|
|
207
197
|
* import { identity } from "effect"
|
|
208
|
-
* import * as assert from "node:assert"
|
|
209
198
|
*
|
|
210
|
-
*
|
|
199
|
+
* identity(5) // => 5
|
|
211
200
|
* ```
|
|
212
201
|
*
|
|
213
202
|
* @category combinators
|
|
@@ -245,12 +234,11 @@ const cast = identity;
|
|
|
245
234
|
*
|
|
246
235
|
* ```ts
|
|
247
236
|
* import { Function } from "effect"
|
|
248
|
-
* import * as assert from "node:assert"
|
|
249
237
|
*
|
|
250
238
|
* const constNull = Function.constant(null)
|
|
251
239
|
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
240
|
+
* constNull() // => null
|
|
241
|
+
* constNull() // => null
|
|
254
242
|
* ```
|
|
255
243
|
*
|
|
256
244
|
* @category constructors
|
|
@@ -268,9 +256,8 @@ const constant = (value) => () => value;
|
|
|
268
256
|
*
|
|
269
257
|
* ```ts
|
|
270
258
|
* import { Function } from "effect"
|
|
271
|
-
* import * as assert from "node:assert"
|
|
272
259
|
*
|
|
273
|
-
*
|
|
260
|
+
* Function.constTrue() // => true
|
|
274
261
|
* ```
|
|
275
262
|
*
|
|
276
263
|
* @category constants
|
|
@@ -288,9 +275,8 @@ const constTrue = constant(true);
|
|
|
288
275
|
*
|
|
289
276
|
* ```ts
|
|
290
277
|
* import { Function } from "effect"
|
|
291
|
-
* import * as assert from "node:assert"
|
|
292
278
|
*
|
|
293
|
-
*
|
|
279
|
+
* Function.constFalse() // => false
|
|
294
280
|
* ```
|
|
295
281
|
*
|
|
296
282
|
* @category constants
|
|
@@ -308,9 +294,8 @@ const constFalse = constant(false);
|
|
|
308
294
|
*
|
|
309
295
|
* ```ts
|
|
310
296
|
* import { Function } from "effect"
|
|
311
|
-
* import * as assert from "node:assert"
|
|
312
297
|
*
|
|
313
|
-
*
|
|
298
|
+
* Function.constNull() // => null
|
|
314
299
|
* ```
|
|
315
300
|
*
|
|
316
301
|
* @category constants
|
|
@@ -328,9 +313,8 @@ const constNull = constant(null);
|
|
|
328
313
|
*
|
|
329
314
|
* ```ts
|
|
330
315
|
* import { Function } from "effect"
|
|
331
|
-
* import * as assert from "node:assert"
|
|
332
316
|
*
|
|
333
|
-
*
|
|
317
|
+
* Function.constUndefined() // => undefined
|
|
334
318
|
* ```
|
|
335
319
|
*
|
|
336
320
|
* @category constants
|
|
@@ -349,12 +333,11 @@ const constUndefined = constant(void 0);
|
|
|
349
333
|
*
|
|
350
334
|
* ```ts
|
|
351
335
|
* import { Function } from "effect"
|
|
352
|
-
* import * as assert from "node:assert"
|
|
353
336
|
*
|
|
354
337
|
* const increment = (n: number) => n + 1
|
|
355
338
|
* const square = (n: number) => n * n
|
|
356
339
|
*
|
|
357
|
-
*
|
|
340
|
+
* Function.compose(increment, square)(2) // => 9
|
|
358
341
|
* ```
|
|
359
342
|
*
|
|
360
343
|
* @see {@link flow} for composing a left-to-right sequence of functions
|
|
@@ -417,13 +400,314 @@ const absurd = (_) => {
|
|
|
417
400
|
* name: hole<string>()
|
|
418
401
|
* })
|
|
419
402
|
*
|
|
420
|
-
* console.log(typeof buildUser) // "function"
|
|
421
403
|
* ```
|
|
422
404
|
*
|
|
423
405
|
* @category utility types
|
|
424
406
|
* @since 2.0.0
|
|
425
407
|
*/
|
|
426
408
|
const hole = cast(absurd);
|
|
409
|
+
/**
|
|
410
|
+
* Creates a predicate that returns `true` only if both predicates are `true`.
|
|
411
|
+
*
|
|
412
|
+
* **When to use**
|
|
413
|
+
*
|
|
414
|
+
* Use when you want to combine `Predicate`s with AND, accepting values that
|
|
415
|
+
* satisfy multiple conditions, including refinements that narrow to an
|
|
416
|
+
* intersection.
|
|
417
|
+
*
|
|
418
|
+
* **Details**
|
|
419
|
+
*
|
|
420
|
+
* Evaluation short-circuits on the first `false`. For refinements, the output
|
|
421
|
+
* type is an intersection.
|
|
422
|
+
*
|
|
423
|
+
* **Example** (Checking both conditions)
|
|
424
|
+
*
|
|
425
|
+
* ```ts
|
|
426
|
+
* import { Predicate } from "effect"
|
|
427
|
+
*
|
|
428
|
+
* const hasAAndB = Predicate.and(
|
|
429
|
+
* Predicate.hasProperty("a"),
|
|
430
|
+
* Predicate.hasProperty("b")
|
|
431
|
+
* )
|
|
432
|
+
*
|
|
433
|
+
* const input: unknown = JSON.parse(`{"a":1,"b":"ok"}`)
|
|
434
|
+
* if (hasAAndB(input)) {
|
|
435
|
+
* // input has both properties at this point
|
|
436
|
+
* const a = input.a
|
|
437
|
+
* const b = input.b
|
|
438
|
+
*
|
|
439
|
+
* const values = [a, b] // => [1, "ok"]
|
|
440
|
+
* }
|
|
441
|
+
* ```
|
|
442
|
+
*
|
|
443
|
+
* @see {@link or}
|
|
444
|
+
* @see {@link not}
|
|
445
|
+
* @category combinators
|
|
446
|
+
* @since 2.0.0
|
|
447
|
+
*/
|
|
448
|
+
const and = dual(2, (a, b) => (data) => a(data) && b(data));
|
|
449
|
+
/**
|
|
450
|
+
* Creates a predicate that returns `true` if either predicate is `true`.
|
|
451
|
+
*
|
|
452
|
+
* **When to use**
|
|
453
|
+
*
|
|
454
|
+
* Use when you want to combine `Predicate`s with OR, accepting values that
|
|
455
|
+
* satisfy at least one condition, including refinements that narrow to a union.
|
|
456
|
+
*
|
|
457
|
+
* **Details**
|
|
458
|
+
*
|
|
459
|
+
* Evaluation short-circuits on the first `true`. For refinements, the output
|
|
460
|
+
* type is a union.
|
|
461
|
+
*
|
|
462
|
+
* **Example** (Checking either condition)
|
|
463
|
+
*
|
|
464
|
+
* ```ts
|
|
465
|
+
* import { Predicate } from "effect"
|
|
466
|
+
*
|
|
467
|
+
* const isStringOrNumber = Predicate.or(Predicate.isString, Predicate.isNumber)
|
|
468
|
+
*
|
|
469
|
+
* isStringOrNumber("a") // => true
|
|
470
|
+
* ```
|
|
471
|
+
*
|
|
472
|
+
* @see {@link and}
|
|
473
|
+
* @see {@link xor}
|
|
474
|
+
* @category combinators
|
|
475
|
+
* @since 2.0.0
|
|
476
|
+
*/
|
|
477
|
+
const or = dual(2, (a, b) => (data) => a(data) || b(data));
|
|
478
|
+
/**
|
|
479
|
+
* Creates a predicate that returns `true` if exactly one predicate is `true`.
|
|
480
|
+
*
|
|
481
|
+
* **When to use**
|
|
482
|
+
*
|
|
483
|
+
* Use when you want to combine two `Predicate`s with exclusive-or semantics.
|
|
484
|
+
*
|
|
485
|
+
* **Details**
|
|
486
|
+
*
|
|
487
|
+
* Returns `true` when results differ.
|
|
488
|
+
*
|
|
489
|
+
* **Example** (Checking exclusive-or conditions)
|
|
490
|
+
*
|
|
491
|
+
* ```ts
|
|
492
|
+
* import { Predicate } from "effect"
|
|
493
|
+
*
|
|
494
|
+
* const isEven = (n: number) => n % 2 === 0
|
|
495
|
+
* const isPositive = (n: number) => n > 0
|
|
496
|
+
* const either = Predicate.xor(isEven, isPositive)
|
|
497
|
+
*
|
|
498
|
+
* either(-2) // => true
|
|
499
|
+
* ```
|
|
500
|
+
*
|
|
501
|
+
* @see {@link or}
|
|
502
|
+
* @see {@link and}
|
|
503
|
+
* @category combinators
|
|
504
|
+
* @since 2.0.0
|
|
505
|
+
*/
|
|
506
|
+
const xor = dual(2, (a, b) => (data) => a(data) !== b(data));
|
|
507
|
+
/**
|
|
508
|
+
* Creates a predicate that returns `true` when both predicates agree.
|
|
509
|
+
*
|
|
510
|
+
* **When to use**
|
|
511
|
+
*
|
|
512
|
+
* Use when you want to check equivalence of two `Predicate`s.
|
|
513
|
+
*
|
|
514
|
+
* **Details**
|
|
515
|
+
*
|
|
516
|
+
* Returns `true` when both results are equal.
|
|
517
|
+
*
|
|
518
|
+
* **Example** (Defining equivalence)
|
|
519
|
+
*
|
|
520
|
+
* ```ts
|
|
521
|
+
* import { Predicate } from "effect"
|
|
522
|
+
*
|
|
523
|
+
* const isEven = (n: number) => n % 2 === 0
|
|
524
|
+
* const same = Predicate.eqv(isEven, isEven)
|
|
525
|
+
*
|
|
526
|
+
* same(3) // => true
|
|
527
|
+
* ```
|
|
528
|
+
*
|
|
529
|
+
* @see {@link xor}
|
|
530
|
+
* @category combinators
|
|
531
|
+
* @since 2.0.0
|
|
532
|
+
*/
|
|
533
|
+
const eqv = dual(2, (a, b) => (data) => a(data) === b(data));
|
|
534
|
+
/**
|
|
535
|
+
* Creates a predicate representing logical implication: if `antecedent`, then `consequent`.
|
|
536
|
+
*
|
|
537
|
+
* **When to use**
|
|
538
|
+
*
|
|
539
|
+
* Use when you need to encode logical implication between `Predicate` rules,
|
|
540
|
+
* where one rule only applies when a precondition holds.
|
|
541
|
+
*
|
|
542
|
+
* **Details**
|
|
543
|
+
*
|
|
544
|
+
* Models constraints like "if A then B" and returns `true` when the antecedent
|
|
545
|
+
* is `false`.
|
|
546
|
+
*
|
|
547
|
+
* **Example** (Checking implication)
|
|
548
|
+
*
|
|
549
|
+
* ```ts
|
|
550
|
+
* import { Predicate } from "effect"
|
|
551
|
+
*
|
|
552
|
+
* const isAdult = (age: number) => age >= 18
|
|
553
|
+
* const canVote = (age: number) => age >= 18
|
|
554
|
+
* const implies = Predicate.implies(isAdult, canVote)
|
|
555
|
+
*
|
|
556
|
+
* implies(16) // => true
|
|
557
|
+
* ```
|
|
558
|
+
*
|
|
559
|
+
* @see {@link and}
|
|
560
|
+
* @see {@link or}
|
|
561
|
+
* @category combinators
|
|
562
|
+
* @since 2.0.0
|
|
563
|
+
*/
|
|
564
|
+
const implies = dual(2, (antecedent, consequent) => (data) => !antecedent(data) || consequent(data));
|
|
565
|
+
/**
|
|
566
|
+
* Creates a predicate that returns `true` when neither predicate is `true`.
|
|
567
|
+
*
|
|
568
|
+
* **When to use**
|
|
569
|
+
*
|
|
570
|
+
* Use when you want to combine two `Predicate`s with logical NOR semantics.
|
|
571
|
+
*
|
|
572
|
+
* **Details**
|
|
573
|
+
*
|
|
574
|
+
* Returns the negation of `or`.
|
|
575
|
+
*
|
|
576
|
+
* **Example** (Checking NOR conditions)
|
|
577
|
+
*
|
|
578
|
+
* ```ts
|
|
579
|
+
* import { Predicate } from "effect"
|
|
580
|
+
*
|
|
581
|
+
* const neither = Predicate.nor(Predicate.isString, Predicate.isNumber)
|
|
582
|
+
*
|
|
583
|
+
* neither(true) // => true
|
|
584
|
+
* ```
|
|
585
|
+
*
|
|
586
|
+
* @see {@link or}
|
|
587
|
+
* @see {@link not}
|
|
588
|
+
* @category combinators
|
|
589
|
+
* @since 2.0.0
|
|
590
|
+
*/
|
|
591
|
+
const nor = dual(2, (a, b) => (data) => !a(data) && !b(data));
|
|
592
|
+
/**
|
|
593
|
+
* Creates a predicate that returns `true` unless both predicates are `true`.
|
|
594
|
+
*
|
|
595
|
+
* **When to use**
|
|
596
|
+
*
|
|
597
|
+
* Use when you want to combine two `Predicate`s with logical NAND semantics.
|
|
598
|
+
*
|
|
599
|
+
* **Details**
|
|
600
|
+
*
|
|
601
|
+
* Returns the negation of `and`.
|
|
602
|
+
*
|
|
603
|
+
* **Example** (Checking NAND conditions)
|
|
604
|
+
*
|
|
605
|
+
* ```ts
|
|
606
|
+
* import { Predicate } from "effect"
|
|
607
|
+
*
|
|
608
|
+
* const notBoth = Predicate.nand(Predicate.isString, Predicate.isNumber)
|
|
609
|
+
*
|
|
610
|
+
* notBoth("a") // => true
|
|
611
|
+
* ```
|
|
612
|
+
*
|
|
613
|
+
* @see {@link and}
|
|
614
|
+
* @see {@link not}
|
|
615
|
+
* @category combinators
|
|
616
|
+
* @since 2.0.0
|
|
617
|
+
*/
|
|
618
|
+
const nand = dual(2, (a, b) => (data) => !a(data) || !b(data));
|
|
619
|
+
/**
|
|
620
|
+
* Checks whether a value is a `function`.
|
|
621
|
+
*
|
|
622
|
+
* **When to use**
|
|
623
|
+
*
|
|
624
|
+
* Use when you need a `Predicate` guard to narrow an `unknown` value to a
|
|
625
|
+
* callable function.
|
|
626
|
+
*
|
|
627
|
+
* **Details**
|
|
628
|
+
*
|
|
629
|
+
* Uses `typeof input === "function"`.
|
|
630
|
+
*
|
|
631
|
+
* **Example** (Guarding functions)
|
|
632
|
+
*
|
|
633
|
+
* ```ts
|
|
634
|
+
* import { Predicate } from "effect"
|
|
635
|
+
*
|
|
636
|
+
* const data: unknown = () => 1
|
|
637
|
+
*
|
|
638
|
+
* if (Predicate.isFunction(data)) {
|
|
639
|
+
* data() // => 1
|
|
640
|
+
* }
|
|
641
|
+
* ```
|
|
642
|
+
*
|
|
643
|
+
* @see {@link isObjectKeyword}
|
|
644
|
+
* @category guards
|
|
645
|
+
* @since 2.0.0
|
|
646
|
+
*/
|
|
647
|
+
function isFunction(input) {
|
|
648
|
+
return typeof input === "function";
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Checks whether a value is an `object` in the JavaScript sense (objects, arrays, functions).
|
|
652
|
+
*
|
|
653
|
+
* **When to use**
|
|
654
|
+
*
|
|
655
|
+
* Use when you need a `Predicate` guard that accepts arrays and functions as
|
|
656
|
+
* well as objects.
|
|
657
|
+
*
|
|
658
|
+
* **Details**
|
|
659
|
+
*
|
|
660
|
+
* Returns `true` for arrays and functions, and `false` for `null`.
|
|
661
|
+
*
|
|
662
|
+
* **Example** (Checking object keywords)
|
|
663
|
+
*
|
|
664
|
+
* ```ts
|
|
665
|
+
* import { Predicate } from "effect"
|
|
666
|
+
*
|
|
667
|
+
* Predicate.isObjectKeyword(() => 1) // => true
|
|
668
|
+
* Predicate.isObjectKeyword(null) // => false
|
|
669
|
+
* ```
|
|
670
|
+
*
|
|
671
|
+
* @see {@link isObject}
|
|
672
|
+
* @see {@link isObjectOrArray}
|
|
673
|
+
* @category guards
|
|
674
|
+
* @since 4.0.0
|
|
675
|
+
*/
|
|
676
|
+
function isObjectKeyword(input) {
|
|
677
|
+
return typeof input === "object" && input !== null || isFunction(input);
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Checks whether a value has a given property key.
|
|
681
|
+
*
|
|
682
|
+
* **When to use**
|
|
683
|
+
*
|
|
684
|
+
* Use when you need a `Predicate` guard for property access on `unknown`
|
|
685
|
+
* values with a simple structural object check.
|
|
686
|
+
*
|
|
687
|
+
* **Details**
|
|
688
|
+
*
|
|
689
|
+
* Uses the `in` operator and `isObjectKeyword`. This does not check property
|
|
690
|
+
* value types.
|
|
691
|
+
*
|
|
692
|
+
* **Example** (Guarding object properties)
|
|
693
|
+
*
|
|
694
|
+
* ```ts
|
|
695
|
+
* import { Predicate } from "effect"
|
|
696
|
+
*
|
|
697
|
+
* const hasName = Predicate.hasProperty("name")
|
|
698
|
+
* const data: unknown = { name: "Ada" }
|
|
699
|
+
*
|
|
700
|
+
* if (hasName(data)) {
|
|
701
|
+
* data.name // => "Ada"
|
|
702
|
+
* }
|
|
703
|
+
* ```
|
|
704
|
+
*
|
|
705
|
+
* @see {@link isTagged}
|
|
706
|
+
* @see {@link isObjectKeyword}
|
|
707
|
+
* @category guards
|
|
708
|
+
* @since 2.0.0
|
|
709
|
+
*/
|
|
710
|
+
const hasProperty = dual(2, (data, property) => isObjectKeyword(data) && property in data);
|
|
427
711
|
function getOrInsertComputed(map, key, callback) {
|
|
428
712
|
if (map.has(key)) return map.get(key);
|
|
429
713
|
const value = callback(key);
|
|
@@ -431,56 +715,72 @@ function getOrInsertComputed(map, key, callback) {
|
|
|
431
715
|
return value;
|
|
432
716
|
}
|
|
433
717
|
/**
|
|
434
|
-
* Drops
|
|
718
|
+
* Drops elements from the start while the predicate holds, returning the rest.
|
|
435
719
|
*
|
|
436
|
-
*
|
|
720
|
+
* **When to use**
|
|
437
721
|
*
|
|
438
|
-
*
|
|
439
|
-
* @returns A new array without the matching prefix.
|
|
440
|
-
* @example
|
|
441
|
-
* ```ts
|
|
442
|
-
* import * as assert from "node:assert"
|
|
443
|
-
* import { dropWhile, pipe } from "@local/eff"
|
|
722
|
+
* Use to remove a leading prefix of elements that satisfy a predicate.
|
|
444
723
|
*
|
|
445
|
-
*
|
|
446
|
-
* assert.deepStrictEqual(dropWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [3, 2, 1])
|
|
724
|
+
* **Details**
|
|
447
725
|
*
|
|
448
|
-
*
|
|
449
|
-
*
|
|
726
|
+
* The predicate receives `(element, index)`.
|
|
727
|
+
*
|
|
728
|
+
* **Example** (Dropping while condition holds)
|
|
729
|
+
*
|
|
730
|
+
* ```ts
|
|
731
|
+
* import { Array } from "effect"
|
|
732
|
+
*
|
|
733
|
+
* Array.dropWhile([1, 2, 3, 4, 5], (x) => x < 4) // => [4, 5]
|
|
450
734
|
* ```
|
|
451
|
-
*
|
|
735
|
+
*
|
|
736
|
+
* @see {@link takeWhile} — keep the matching prefix instead
|
|
737
|
+
* @see {@link drop} — drop a fixed count
|
|
738
|
+
*
|
|
739
|
+
* @category getters
|
|
740
|
+
* @since 2.0.0
|
|
452
741
|
*/
|
|
453
|
-
const dropWhile = dual(2, (
|
|
454
|
-
const
|
|
742
|
+
const dropWhile = dual(2, (self, predicate) => {
|
|
743
|
+
const input = Array.isArray(self) ? self : Array.from(self);
|
|
744
|
+
const len = input.length;
|
|
455
745
|
let idx = 0;
|
|
456
|
-
while (idx < len &&
|
|
457
|
-
return
|
|
746
|
+
while (idx < len && predicate(input[idx], idx)) idx++;
|
|
747
|
+
return input.slice(idx);
|
|
458
748
|
});
|
|
459
749
|
/**
|
|
460
|
-
* Takes
|
|
750
|
+
* Takes elements from the start while the predicate holds, stopping at the
|
|
751
|
+
* first element that fails.
|
|
461
752
|
*
|
|
462
|
-
*
|
|
753
|
+
* **When to use**
|
|
463
754
|
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
* import * as assert from "node:assert"
|
|
469
|
-
* import { pipe, takeWhile } from "@local/eff"
|
|
755
|
+
* Use to keep the leading elements of an iterable while each element satisfies
|
|
756
|
+
* a predicate, returning the retained prefix as an array.
|
|
757
|
+
*
|
|
758
|
+
* **Details**
|
|
470
759
|
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
760
|
+
* Supports refinements for type narrowing. The predicate receives
|
|
761
|
+
* `(element, index)`.
|
|
473
762
|
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
763
|
+
* **Example** (Taking while condition holds)
|
|
764
|
+
*
|
|
765
|
+
* ```ts
|
|
766
|
+
* import { Array } from "effect"
|
|
767
|
+
*
|
|
768
|
+
* Array.takeWhile([1, 3, 2, 4, 1, 2], (x) => x < 4) // => [1, 3, 2]
|
|
476
769
|
* ```
|
|
477
|
-
*
|
|
770
|
+
*
|
|
771
|
+
* @see {@link take} for keeping a fixed number of leading elements
|
|
772
|
+
* @see {@link dropWhile} for removing the matching prefix and keeping the rest
|
|
773
|
+
* @see {@link span} for splitting the matching prefix from the remaining elements
|
|
774
|
+
*
|
|
775
|
+
* @category getters
|
|
776
|
+
* @since 2.0.0
|
|
478
777
|
*/
|
|
479
|
-
const takeWhile = dual(2, (
|
|
480
|
-
const
|
|
778
|
+
const takeWhile = dual(2, (self, predicate) => {
|
|
779
|
+
const input = Array.isArray(self) ? self : Array.from(self);
|
|
780
|
+
const len = input.length;
|
|
481
781
|
let idx = 0;
|
|
482
|
-
while (idx < len &&
|
|
483
|
-
return
|
|
782
|
+
while (idx < len && predicate(input[idx], idx)) idx++;
|
|
783
|
+
return input.slice(0, idx);
|
|
484
784
|
});
|
|
485
785
|
|
|
486
786
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/var",
|
|
3
|
-
"version": "5.24.
|
|
3
|
+
"version": "5.24.1",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module for static analysis of variables.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@eslint-react/ast": "5.24.
|
|
33
|
-
"@eslint-react/eslint": "5.24.
|
|
32
|
+
"@eslint-react/ast": "5.24.1",
|
|
33
|
+
"@eslint-react/eslint": "5.24.1",
|
|
34
34
|
"@typescript-eslint/scope-manager": "^8.71.0",
|
|
35
35
|
"@typescript-eslint/types": "^8.71.0",
|
|
36
36
|
"@typescript-eslint/utils": "^8.71.0",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@local/eff": "0.0.0",
|
|
42
42
|
"@local/testkit": "0.0.0",
|
|
43
43
|
"@typescript-eslint/typescript-estree": "^8.71.0",
|
|
44
|
-
"eslint": "^10.
|
|
44
|
+
"eslint": "^10.12.0",
|
|
45
45
|
"tsdown": "^0.23.0",
|
|
46
46
|
"typescript": "6.0.3",
|
|
47
47
|
"vitest": "^5.0.3"
|