effect 3.17.9 → 3.17.10
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/cjs/Arbitrary.js +5 -2
- package/dist/cjs/Arbitrary.js.map +1 -1
- package/dist/cjs/Either.js.map +1 -1
- package/dist/cjs/JSONSchema.js +307 -364
- package/dist/cjs/JSONSchema.js.map +1 -1
- package/dist/cjs/ParseResult.js +1 -1
- package/dist/cjs/ParseResult.js.map +1 -1
- package/dist/cjs/Schema.js +17 -14
- package/dist/cjs/Schema.js.map +1 -1
- package/dist/cjs/SchemaAST.js +27 -25
- package/dist/cjs/SchemaAST.js.map +1 -1
- package/dist/cjs/internal/core-effect.js +6 -6
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/cjs/internal/version.js.map +1 -1
- package/dist/dts/Effect.d.ts +4 -4
- package/dist/dts/Either.d.ts +96 -96
- package/dist/dts/Either.d.ts.map +1 -1
- package/dist/dts/JSONSchema.d.ts.map +1 -1
- package/dist/dts/STM.d.ts +2 -2
- package/dist/dts/Schema.d.ts.map +1 -1
- package/dist/dts/SchemaAST.d.ts +2 -0
- package/dist/dts/SchemaAST.d.ts.map +1 -1
- package/dist/esm/Arbitrary.js +5 -2
- package/dist/esm/Arbitrary.js.map +1 -1
- package/dist/esm/Either.js.map +1 -1
- package/dist/esm/JSONSchema.js +307 -364
- package/dist/esm/JSONSchema.js.map +1 -1
- package/dist/esm/ParseResult.js +1 -1
- package/dist/esm/ParseResult.js.map +1 -1
- package/dist/esm/Schema.js +17 -14
- package/dist/esm/Schema.js.map +1 -1
- package/dist/esm/SchemaAST.js +27 -25
- package/dist/esm/SchemaAST.js.map +1 -1
- package/dist/esm/internal/core-effect.js +6 -6
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/dist/esm/internal/version.js.map +1 -1
- package/package.json +1 -1
- package/src/Arbitrary.ts +4 -2
- package/src/Effect.ts +4 -4
- package/src/Either.ts +132 -132
- package/src/JSONSchema.ts +373 -332
- package/src/ParseResult.ts +1 -1
- package/src/STM.ts +2 -2
- package/src/Schema.ts +19 -12
- package/src/SchemaAST.ts +24 -31
- package/src/internal/core-effect.ts +6 -6
- package/src/internal/version.ts +1 -1
package/src/Either.ts
CHANGED
|
@@ -22,7 +22,7 @@ import * as Gen from "./Utils.js"
|
|
|
22
22
|
* @category models
|
|
23
23
|
* @since 2.0.0
|
|
24
24
|
*/
|
|
25
|
-
export type Either<
|
|
25
|
+
export type Either<A, E = never> = Left<E, A> | Right<E, A>
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @category symbols
|
|
@@ -41,13 +41,13 @@ export type TypeId = typeof TypeId
|
|
|
41
41
|
* @category models
|
|
42
42
|
* @since 2.0.0
|
|
43
43
|
*/
|
|
44
|
-
export interface Left<out
|
|
44
|
+
export interface Left<out E, out A> extends Pipeable, Inspectable {
|
|
45
45
|
readonly _tag: "Left"
|
|
46
46
|
readonly _op: "Left"
|
|
47
|
-
readonly left:
|
|
47
|
+
readonly left: E
|
|
48
48
|
readonly [TypeId]: {
|
|
49
|
-
readonly _R: Covariant<
|
|
50
|
-
readonly _L: Covariant<
|
|
49
|
+
readonly _R: Covariant<A>
|
|
50
|
+
readonly _L: Covariant<E>
|
|
51
51
|
}
|
|
52
52
|
[Unify.typeSymbol]?: unknown
|
|
53
53
|
[Unify.unifySymbol]?: EitherUnify<this>
|
|
@@ -59,13 +59,13 @@ export interface Left<out L, out R> extends Pipeable, Inspectable {
|
|
|
59
59
|
* @category models
|
|
60
60
|
* @since 2.0.0
|
|
61
61
|
*/
|
|
62
|
-
export interface Right<out
|
|
62
|
+
export interface Right<out E, out A> extends Pipeable, Inspectable {
|
|
63
63
|
readonly _tag: "Right"
|
|
64
64
|
readonly _op: "Right"
|
|
65
|
-
readonly right:
|
|
65
|
+
readonly right: A
|
|
66
66
|
readonly [TypeId]: {
|
|
67
|
-
readonly _R: Covariant<
|
|
68
|
-
readonly _L: Covariant<
|
|
67
|
+
readonly _R: Covariant<A>
|
|
68
|
+
readonly _L: Covariant<E>
|
|
69
69
|
}
|
|
70
70
|
[Unify.typeSymbol]?: unknown
|
|
71
71
|
[Unify.unifySymbol]?: EitherUnify<this>
|
|
@@ -117,7 +117,7 @@ export declare namespace Either {
|
|
|
117
117
|
* @category constructors
|
|
118
118
|
* @since 2.0.0
|
|
119
119
|
*/
|
|
120
|
-
export const right: <
|
|
120
|
+
export const right: <A>(a: A) => Either<A> = either.right
|
|
121
121
|
|
|
122
122
|
const void_: Either<void> = right(void 0)
|
|
123
123
|
export {
|
|
@@ -135,7 +135,7 @@ export {
|
|
|
135
135
|
* @category constructors
|
|
136
136
|
* @since 2.0.0
|
|
137
137
|
*/
|
|
138
|
-
export const left: <
|
|
138
|
+
export const left: <E>(e: E) => Either<never, E> = either.left
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
141
|
* Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use
|
|
@@ -170,7 +170,7 @@ export const fromNullable: {
|
|
|
170
170
|
* @category constructors
|
|
171
171
|
* @since 2.0.0
|
|
172
172
|
*/
|
|
173
|
-
<
|
|
173
|
+
<A, E>(onNullable: (right: A) => E): (self: A) => Either<NonNullable<A>, E>
|
|
174
174
|
/**
|
|
175
175
|
* Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use
|
|
176
176
|
* the provided default as a `Left`.
|
|
@@ -187,10 +187,10 @@ export const fromNullable: {
|
|
|
187
187
|
* @category constructors
|
|
188
188
|
* @since 2.0.0
|
|
189
189
|
*/
|
|
190
|
-
<
|
|
190
|
+
<A, E>(self: A, onNullable: (right: A) => E): Either<NonNullable<A>, E>
|
|
191
191
|
} = dual(
|
|
192
192
|
2,
|
|
193
|
-
<
|
|
193
|
+
<A, E>(self: A, onNullable: (right: A) => E): Either<NonNullable<A>, E> =>
|
|
194
194
|
self == null ? left(onNullable(self)) : right(self)
|
|
195
195
|
)
|
|
196
196
|
|
|
@@ -221,7 +221,7 @@ export const fromOption: {
|
|
|
221
221
|
* @category constructors
|
|
222
222
|
* @since 2.0.0
|
|
223
223
|
*/
|
|
224
|
-
<
|
|
224
|
+
<E>(onNone: () => E): <A>(self: Option<A>) => Either<A, E>
|
|
225
225
|
/**
|
|
226
226
|
* @example
|
|
227
227
|
* ```ts
|
|
@@ -235,21 +235,21 @@ export const fromOption: {
|
|
|
235
235
|
* @category constructors
|
|
236
236
|
* @since 2.0.0
|
|
237
237
|
*/
|
|
238
|
-
<
|
|
238
|
+
<A, E>(self: Option<A>, onNone: () => E): Either<A, E>
|
|
239
239
|
} = either.fromOption
|
|
240
240
|
|
|
241
241
|
const try_: {
|
|
242
|
-
<
|
|
242
|
+
<A, E>(
|
|
243
243
|
options: {
|
|
244
|
-
readonly try: LazyArg<
|
|
245
|
-
readonly catch: (error: unknown) =>
|
|
244
|
+
readonly try: LazyArg<A>
|
|
245
|
+
readonly catch: (error: unknown) => E
|
|
246
246
|
}
|
|
247
|
-
): Either<
|
|
248
|
-
<
|
|
249
|
-
} = (<
|
|
250
|
-
evaluate: LazyArg<
|
|
251
|
-
readonly try: LazyArg<
|
|
252
|
-
readonly catch: (error: unknown) =>
|
|
247
|
+
): Either<A, E>
|
|
248
|
+
<A>(evaluate: LazyArg<A>): Either<A, unknown>
|
|
249
|
+
} = (<A, E>(
|
|
250
|
+
evaluate: LazyArg<A> | {
|
|
251
|
+
readonly try: LazyArg<A>
|
|
252
|
+
readonly catch: (error: unknown) => E
|
|
253
253
|
}
|
|
254
254
|
) => {
|
|
255
255
|
if (isFunction(evaluate)) {
|
|
@@ -311,7 +311,7 @@ export const isEither: (input: unknown) => input is Either<unknown, unknown> = e
|
|
|
311
311
|
* @category guards
|
|
312
312
|
* @since 2.0.0
|
|
313
313
|
*/
|
|
314
|
-
export const isLeft: <
|
|
314
|
+
export const isLeft: <A, E>(self: Either<A, E>) => self is Left<E, A> = either.isLeft
|
|
315
315
|
|
|
316
316
|
/**
|
|
317
317
|
* Determine if a `Either` is a `Right`.
|
|
@@ -328,7 +328,7 @@ export const isLeft: <R, L>(self: Either<R, L>) => self is Left<L, R> = either.i
|
|
|
328
328
|
* @category guards
|
|
329
329
|
* @since 2.0.0
|
|
330
330
|
*/
|
|
331
|
-
export const isRight: <
|
|
331
|
+
export const isRight: <A, E>(self: Either<A, E>) => self is Right<E, A> = either.isRight
|
|
332
332
|
|
|
333
333
|
/**
|
|
334
334
|
* Converts a `Either` to an `Option` discarding the `Left`.
|
|
@@ -345,7 +345,7 @@ export const isRight: <R, L>(self: Either<R, L>) => self is Right<L, R> = either
|
|
|
345
345
|
* @category getters
|
|
346
346
|
* @since 2.0.0
|
|
347
347
|
*/
|
|
348
|
-
export const getRight: <
|
|
348
|
+
export const getRight: <A, E>(self: Either<A, E>) => Option<A> = either.getRight
|
|
349
349
|
|
|
350
350
|
/**
|
|
351
351
|
* Converts a `Either` to an `Option` discarding the value.
|
|
@@ -362,16 +362,16 @@ export const getRight: <R, L>(self: Either<R, L>) => Option<R> = either.getRight
|
|
|
362
362
|
* @category getters
|
|
363
363
|
* @since 2.0.0
|
|
364
364
|
*/
|
|
365
|
-
export const getLeft: <
|
|
365
|
+
export const getLeft: <A, E>(self: Either<A, E>) => Option<E> = either.getLeft
|
|
366
366
|
|
|
367
367
|
/**
|
|
368
368
|
* @category equivalence
|
|
369
369
|
* @since 2.0.0
|
|
370
370
|
*/
|
|
371
|
-
export const getEquivalence = <
|
|
372
|
-
right: Equivalence.Equivalence<
|
|
373
|
-
left: Equivalence.Equivalence<
|
|
374
|
-
}): Equivalence.Equivalence<Either<
|
|
371
|
+
export const getEquivalence = <A, E>({ left, right }: {
|
|
372
|
+
right: Equivalence.Equivalence<A>
|
|
373
|
+
left: Equivalence.Equivalence<E>
|
|
374
|
+
}): Equivalence.Equivalence<Either<A, E>> =>
|
|
375
375
|
Equivalence.make((x, y) =>
|
|
376
376
|
isLeft(x) ?
|
|
377
377
|
isLeft(y) && left(x.left, y.left) :
|
|
@@ -387,29 +387,29 @@ export const mapBoth: {
|
|
|
387
387
|
* @category mapping
|
|
388
388
|
* @since 2.0.0
|
|
389
389
|
*/
|
|
390
|
-
<
|
|
390
|
+
<E, E2, A, A2>(
|
|
391
391
|
options: {
|
|
392
|
-
readonly onLeft: (left:
|
|
393
|
-
readonly onRight: (right:
|
|
392
|
+
readonly onLeft: (left: E) => E2
|
|
393
|
+
readonly onRight: (right: A) => A2
|
|
394
394
|
}
|
|
395
|
-
): (self: Either<
|
|
395
|
+
): (self: Either<A, E>) => Either<A2, E2>
|
|
396
396
|
/**
|
|
397
397
|
* @category mapping
|
|
398
398
|
* @since 2.0.0
|
|
399
399
|
*/
|
|
400
|
-
<
|
|
401
|
-
self: Either<
|
|
400
|
+
<A, E, E2, A2>(
|
|
401
|
+
self: Either<A, E>,
|
|
402
402
|
options: {
|
|
403
|
-
readonly onLeft: (left:
|
|
404
|
-
readonly onRight: (right:
|
|
403
|
+
readonly onLeft: (left: E) => E2
|
|
404
|
+
readonly onRight: (right: A) => A2
|
|
405
405
|
}
|
|
406
|
-
): Either<
|
|
406
|
+
): Either<A2, E2>
|
|
407
407
|
} = dual(
|
|
408
408
|
2,
|
|
409
|
-
<
|
|
410
|
-
readonly onLeft: (left:
|
|
411
|
-
readonly onRight: (right:
|
|
412
|
-
}): Either<
|
|
409
|
+
<A, E, E2, A2>(self: Either<A, E>, { onLeft, onRight }: {
|
|
410
|
+
readonly onLeft: (left: E) => E2
|
|
411
|
+
readonly onRight: (right: A) => A2
|
|
412
|
+
}): Either<A2, E2> => isLeft(self) ? left(onLeft(self.left)) : right(onRight(self.right))
|
|
413
413
|
)
|
|
414
414
|
|
|
415
415
|
/**
|
|
@@ -425,17 +425,17 @@ export const mapLeft: {
|
|
|
425
425
|
* @category mapping
|
|
426
426
|
* @since 2.0.0
|
|
427
427
|
*/
|
|
428
|
-
<
|
|
428
|
+
<E, E2>(f: (left: E) => E2): <A>(self: Either<A, E>) => Either<A, E2>
|
|
429
429
|
/**
|
|
430
430
|
* Maps the `Left` side of an `Either` value to a new `Either` value.
|
|
431
431
|
*
|
|
432
432
|
* @category mapping
|
|
433
433
|
* @since 2.0.0
|
|
434
434
|
*/
|
|
435
|
-
<
|
|
435
|
+
<A, E, E2>(self: Either<A, E>, f: (left: E) => E2): Either<A, E2>
|
|
436
436
|
} = dual(
|
|
437
437
|
2,
|
|
438
|
-
<
|
|
438
|
+
<A, E, E2>(self: Either<A, E>, f: (left: E) => E2): Either<A, E2> =>
|
|
439
439
|
isLeft(self) ? left(f(self.left)) : right(self.right)
|
|
440
440
|
)
|
|
441
441
|
|
|
@@ -452,17 +452,17 @@ export const map: {
|
|
|
452
452
|
* @category mapping
|
|
453
453
|
* @since 2.0.0
|
|
454
454
|
*/
|
|
455
|
-
<
|
|
455
|
+
<A, A2>(f: (right: A) => A2): <E>(self: Either<A, E>) => Either<A2, E>
|
|
456
456
|
/**
|
|
457
457
|
* Maps the `Right` side of an `Either` value to a new `Either` value.
|
|
458
458
|
*
|
|
459
459
|
* @category mapping
|
|
460
460
|
* @since 2.0.0
|
|
461
461
|
*/
|
|
462
|
-
<
|
|
462
|
+
<A, E, A2>(self: Either<A, E>, f: (right: A) => A2): Either<A2, E>
|
|
463
463
|
} = dual(
|
|
464
464
|
2,
|
|
465
|
-
<
|
|
465
|
+
<A, E, A2>(self: Either<A, E>, f: (right: A) => A2): Either<A2, E> =>
|
|
466
466
|
isRight(self) ? right(f(self.right)) : left(self.left)
|
|
467
467
|
)
|
|
468
468
|
|
|
@@ -513,12 +513,12 @@ export const match: {
|
|
|
513
513
|
* @category pattern matching
|
|
514
514
|
* @since 2.0.0
|
|
515
515
|
*/
|
|
516
|
-
<
|
|
516
|
+
<E, B, A, C = B>(
|
|
517
517
|
options: {
|
|
518
|
-
readonly onLeft: (left:
|
|
519
|
-
readonly onRight: (right:
|
|
518
|
+
readonly onLeft: (left: E) => B
|
|
519
|
+
readonly onRight: (right: A) => C
|
|
520
520
|
}
|
|
521
|
-
): (self: Either<
|
|
521
|
+
): (self: Either<A, E>) => B | C
|
|
522
522
|
/**
|
|
523
523
|
* Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,
|
|
524
524
|
* if the value is a `Right` the inner value is applied to the `onRight` function.
|
|
@@ -542,18 +542,18 @@ export const match: {
|
|
|
542
542
|
* @category pattern matching
|
|
543
543
|
* @since 2.0.0
|
|
544
544
|
*/
|
|
545
|
-
<
|
|
546
|
-
self: Either<
|
|
545
|
+
<A, E, B, C = B>(
|
|
546
|
+
self: Either<A, E>,
|
|
547
547
|
options: {
|
|
548
|
-
readonly onLeft: (left:
|
|
549
|
-
readonly onRight: (right:
|
|
548
|
+
readonly onLeft: (left: E) => B
|
|
549
|
+
readonly onRight: (right: A) => C
|
|
550
550
|
}
|
|
551
551
|
): B | C
|
|
552
552
|
} = dual(
|
|
553
553
|
2,
|
|
554
|
-
<
|
|
555
|
-
readonly onLeft: (left:
|
|
556
|
-
readonly onRight: (right:
|
|
554
|
+
<A, E, B, C = B>(self: Either<A, E>, { onLeft, onRight }: {
|
|
555
|
+
readonly onLeft: (left: E) => B
|
|
556
|
+
readonly onRight: (right: A) => C
|
|
557
557
|
}): B | C => isLeft(self) ? onLeft(self.left) : onRight(self.right)
|
|
558
558
|
)
|
|
559
559
|
|
|
@@ -754,10 +754,10 @@ export const filterOrLeft: {
|
|
|
754
754
|
* @since 2.0.0
|
|
755
755
|
* @category filtering & conditionals
|
|
756
756
|
*/
|
|
757
|
-
<
|
|
758
|
-
refinement: Refinement<NoInfer<
|
|
759
|
-
orLeftWith: (right: NoInfer<
|
|
760
|
-
): <
|
|
757
|
+
<A, B extends A, E2>(
|
|
758
|
+
refinement: Refinement<NoInfer<A>, B>,
|
|
759
|
+
orLeftWith: (right: NoInfer<A>) => E2
|
|
760
|
+
): <E>(self: Either<A, E>) => Either<B, E2 | E>
|
|
761
761
|
/**
|
|
762
762
|
* Filter the right value with the provided function.
|
|
763
763
|
* If the predicate fails, set the left value with the result of the provided function.
|
|
@@ -788,7 +788,7 @@ export const filterOrLeft: {
|
|
|
788
788
|
* @since 2.0.0
|
|
789
789
|
* @category filtering & conditionals
|
|
790
790
|
*/
|
|
791
|
-
<
|
|
791
|
+
<A, E2>(predicate: Predicate<NoInfer<A>>, orLeftWith: (right: NoInfer<A>) => E2): <E>(self: Either<A, E>) => Either<A, E2 | E>
|
|
792
792
|
/**
|
|
793
793
|
* Filter the right value with the provided function.
|
|
794
794
|
* If the predicate fails, set the left value with the result of the provided function.
|
|
@@ -819,11 +819,11 @@ export const filterOrLeft: {
|
|
|
819
819
|
* @since 2.0.0
|
|
820
820
|
* @category filtering & conditionals
|
|
821
821
|
*/
|
|
822
|
-
<
|
|
823
|
-
self: Either<
|
|
824
|
-
refinement: Refinement<
|
|
825
|
-
orLeftWith: (right:
|
|
826
|
-
): Either<B,
|
|
822
|
+
<A, E, B extends A, E2>(
|
|
823
|
+
self: Either<A, E>,
|
|
824
|
+
refinement: Refinement<A, B>,
|
|
825
|
+
orLeftWith: (right: A) => E2
|
|
826
|
+
): Either<B, E | E2>
|
|
827
827
|
/**
|
|
828
828
|
* Filter the right value with the provided function.
|
|
829
829
|
* If the predicate fails, set the left value with the result of the provided function.
|
|
@@ -854,18 +854,18 @@ export const filterOrLeft: {
|
|
|
854
854
|
* @since 2.0.0
|
|
855
855
|
* @category filtering & conditionals
|
|
856
856
|
*/
|
|
857
|
-
<
|
|
858
|
-
} = dual(3, <
|
|
859
|
-
self: Either<
|
|
860
|
-
predicate: Predicate<
|
|
861
|
-
orLeftWith: (right:
|
|
862
|
-
): Either<
|
|
857
|
+
<A, E, E2>(self: Either<A, E>, predicate: Predicate<A>, orLeftWith: (right: A) => E2): Either<A, E | E2>
|
|
858
|
+
} = dual(3, <A, E, E2>(
|
|
859
|
+
self: Either<A, E>,
|
|
860
|
+
predicate: Predicate<A>,
|
|
861
|
+
orLeftWith: (right: A) => E2
|
|
862
|
+
): Either<A, E | E2> => flatMap(self, (r) => predicate(r) ? right(r) : left(orLeftWith(r))))
|
|
863
863
|
|
|
864
864
|
/**
|
|
865
865
|
* @category getters
|
|
866
866
|
* @since 2.0.0
|
|
867
867
|
*/
|
|
868
|
-
export const merge: <
|
|
868
|
+
export const merge: <A, E>(self: Either<A, E>) => E | A = match({
|
|
869
869
|
onLeft: identity,
|
|
870
870
|
onRight: identity
|
|
871
871
|
})
|
|
@@ -901,7 +901,7 @@ export const getOrElse: {
|
|
|
901
901
|
* @category getters
|
|
902
902
|
* @since 2.0.0
|
|
903
903
|
*/
|
|
904
|
-
<
|
|
904
|
+
<E, A2>(onLeft: (left: E) => A2): <A>(self: Either<A, E>) => A2 | A
|
|
905
905
|
/**
|
|
906
906
|
* Returns the wrapped value if it's a `Right` or a default value if is a `Left`.
|
|
907
907
|
*
|
|
@@ -917,10 +917,10 @@ export const getOrElse: {
|
|
|
917
917
|
* @category getters
|
|
918
918
|
* @since 2.0.0
|
|
919
919
|
*/
|
|
920
|
-
<
|
|
920
|
+
<A, E, A2>(self: Either<A, E>, onLeft: (left: E) => A2): A | A2
|
|
921
921
|
} = dual(
|
|
922
922
|
2,
|
|
923
|
-
<
|
|
923
|
+
<A, E, A2>(self: Either<A, E>, onLeft: (left: E) => A2): A | A2 => isLeft(self) ? onLeft(self.left) : self.right
|
|
924
924
|
)
|
|
925
925
|
|
|
926
926
|
/**
|
|
@@ -936,7 +936,7 @@ export const getOrElse: {
|
|
|
936
936
|
* @category getters
|
|
937
937
|
* @since 2.0.0
|
|
938
938
|
*/
|
|
939
|
-
export const getOrNull: <
|
|
939
|
+
export const getOrNull: <A, E>(self: Either<A, E>) => A | null = getOrElse(constNull)
|
|
940
940
|
|
|
941
941
|
/**
|
|
942
942
|
* @example
|
|
@@ -951,7 +951,7 @@ export const getOrNull: <R, L>(self: Either<R, L>) => R | null = getOrElse(const
|
|
|
951
951
|
* @category getters
|
|
952
952
|
* @since 2.0.0
|
|
953
953
|
*/
|
|
954
|
-
export const getOrUndefined: <
|
|
954
|
+
export const getOrUndefined: <A, E>(self: Either<A, E>) => A | undefined = getOrElse(constUndefined)
|
|
955
955
|
|
|
956
956
|
/**
|
|
957
957
|
* Extracts the value of an `Either` or throws if the `Either` is `Left`.
|
|
@@ -994,7 +994,7 @@ export const getOrThrowWith: {
|
|
|
994
994
|
* @category getters
|
|
995
995
|
* @since 2.0.0
|
|
996
996
|
*/
|
|
997
|
-
<
|
|
997
|
+
<E>(onLeft: (left: E) => unknown): <A>(self: Either<A, E>) => A
|
|
998
998
|
/**
|
|
999
999
|
* Extracts the value of an `Either` or throws if the `Either` is `Left`.
|
|
1000
1000
|
*
|
|
@@ -1015,8 +1015,8 @@ export const getOrThrowWith: {
|
|
|
1015
1015
|
* @category getters
|
|
1016
1016
|
* @since 2.0.0
|
|
1017
1017
|
*/
|
|
1018
|
-
<
|
|
1019
|
-
} = dual(2, <
|
|
1018
|
+
<A, E>(self: Either<A, E>, onLeft: (left: E) => unknown): A
|
|
1019
|
+
} = dual(2, <A, E>(self: Either<A, E>, onLeft: (left: E) => unknown): A => {
|
|
1020
1020
|
if (isRight(self)) {
|
|
1021
1021
|
return self.right
|
|
1022
1022
|
}
|
|
@@ -1043,7 +1043,7 @@ export const getOrThrowWith: {
|
|
|
1043
1043
|
* @category getters
|
|
1044
1044
|
* @since 2.0.0
|
|
1045
1045
|
*/
|
|
1046
|
-
export const getOrThrow: <
|
|
1046
|
+
export const getOrThrow: <A, E>(self: Either<A, E>) => A = getOrThrowWith(() =>
|
|
1047
1047
|
new Error("getOrThrow called on a Left")
|
|
1048
1048
|
)
|
|
1049
1049
|
|
|
@@ -1060,17 +1060,17 @@ export const orElse: {
|
|
|
1060
1060
|
* @category error handling
|
|
1061
1061
|
* @since 2.0.0
|
|
1062
1062
|
*/
|
|
1063
|
-
<
|
|
1063
|
+
<E, A2, E2>(that: (left: E) => Either<A2, E2>): <A>(self: Either<A, E>) => Either<A | A2, E2>
|
|
1064
1064
|
/**
|
|
1065
1065
|
* Returns `self` if it is a `Right` or `that` otherwise.
|
|
1066
1066
|
*
|
|
1067
1067
|
* @category error handling
|
|
1068
1068
|
* @since 2.0.0
|
|
1069
1069
|
*/
|
|
1070
|
-
<
|
|
1070
|
+
<A, E, A2, E2>(self: Either<A, E>, that: (left: E) => Either<A2, E2>): Either<A | A2, E2>
|
|
1071
1071
|
} = dual(
|
|
1072
1072
|
2,
|
|
1073
|
-
<
|
|
1073
|
+
<A, E, A2, E2>(self: Either<A, E>, that: (left: E) => Either<A2, E2>): Either<A | A2, E2> =>
|
|
1074
1074
|
isLeft(self) ? that(self.left) : right(self.right)
|
|
1075
1075
|
)
|
|
1076
1076
|
|
|
@@ -1083,15 +1083,15 @@ export const flatMap: {
|
|
|
1083
1083
|
* @category sequencing
|
|
1084
1084
|
* @since 2.0.0
|
|
1085
1085
|
*/
|
|
1086
|
-
<
|
|
1086
|
+
<A, A2, E2>(f: (right: A) => Either<A2, E2>): <E>(self: Either<A, E>) => Either<A2, E | E2>
|
|
1087
1087
|
/**
|
|
1088
1088
|
* @category sequencing
|
|
1089
1089
|
* @since 2.0.0
|
|
1090
1090
|
*/
|
|
1091
|
-
<
|
|
1091
|
+
<A, E, A2, E2>(self: Either<A, E>, f: (right: A) => Either<A2, E2>): Either<A2, E | E2>
|
|
1092
1092
|
} = dual(
|
|
1093
1093
|
2,
|
|
1094
|
-
<
|
|
1094
|
+
<A, E, A2, E2>(self: Either<A, E>, f: (right: A) => Either<A2, E2>): Either<A2, E | E2> =>
|
|
1095
1095
|
isLeft(self) ? left(self.left) : f(self.right)
|
|
1096
1096
|
)
|
|
1097
1097
|
|
|
@@ -1108,59 +1108,59 @@ export const andThen: {
|
|
|
1108
1108
|
* @category sequencing
|
|
1109
1109
|
* @since 2.0.0
|
|
1110
1110
|
*/
|
|
1111
|
-
<
|
|
1111
|
+
<A, A2, E2>(f: (right: A) => Either<A2, E2>): <E>(self: Either<A, E>) => Either<A2, E | E2>
|
|
1112
1112
|
/**
|
|
1113
1113
|
* Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.
|
|
1114
1114
|
*
|
|
1115
1115
|
* @category sequencing
|
|
1116
1116
|
* @since 2.0.0
|
|
1117
1117
|
*/
|
|
1118
|
-
<
|
|
1118
|
+
<A2, E2>(f: Either<A2, E2>): <E, A>(self: Either<A, E>) => Either<A2, E | E2>
|
|
1119
1119
|
/**
|
|
1120
1120
|
* Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.
|
|
1121
1121
|
*
|
|
1122
1122
|
* @category sequencing
|
|
1123
1123
|
* @since 2.0.0
|
|
1124
1124
|
*/
|
|
1125
|
-
<
|
|
1125
|
+
<A, A2>(f: (right: A) => A2): <E>(self: Either<A, E>) => Either<A2, E>
|
|
1126
1126
|
/**
|
|
1127
1127
|
* Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.
|
|
1128
1128
|
*
|
|
1129
1129
|
* @category sequencing
|
|
1130
1130
|
* @since 2.0.0
|
|
1131
1131
|
*/
|
|
1132
|
-
<
|
|
1132
|
+
<A2>(right: NotFunction<A2>): <A, E>(self: Either<A, E>) => Either<A2, E>
|
|
1133
1133
|
/**
|
|
1134
1134
|
* Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.
|
|
1135
1135
|
*
|
|
1136
1136
|
* @category sequencing
|
|
1137
1137
|
* @since 2.0.0
|
|
1138
1138
|
*/
|
|
1139
|
-
<
|
|
1139
|
+
<A, E, A2, E2>(self: Either<A, E>, f: (right: A) => Either<A2, E2>): Either<A2, E | E2>
|
|
1140
1140
|
/**
|
|
1141
1141
|
* Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.
|
|
1142
1142
|
*
|
|
1143
1143
|
* @category sequencing
|
|
1144
1144
|
* @since 2.0.0
|
|
1145
1145
|
*/
|
|
1146
|
-
<
|
|
1146
|
+
<A, E, A2, E2>(self: Either<A, E>, f: Either<A2, E2>): Either<A2, E | E2>
|
|
1147
1147
|
/**
|
|
1148
1148
|
* Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.
|
|
1149
1149
|
*
|
|
1150
1150
|
* @category sequencing
|
|
1151
1151
|
* @since 2.0.0
|
|
1152
1152
|
*/
|
|
1153
|
-
<
|
|
1153
|
+
<A, E, A2>(self: Either<A, E>, f: (right: A) => A2): Either<A2, E>
|
|
1154
1154
|
/**
|
|
1155
1155
|
* Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.
|
|
1156
1156
|
*
|
|
1157
1157
|
* @category sequencing
|
|
1158
1158
|
* @since 2.0.0
|
|
1159
1159
|
*/
|
|
1160
|
-
<
|
|
1160
|
+
<A, E, A2>(self: Either<A, E>, f: NotFunction<A2>): Either<A2, E>
|
|
1161
1161
|
} = dual(
|
|
1162
1162
|
2,
|
|
1163
|
-
<
|
|
1163
|
+
<A, E, A2, E2>(self: Either<A, E>, f: (right: A) => Either<A2, E2> | Either<A2, E2>): Either<A2, E | E2> =>
|
|
1164
1164
|
flatMap(self, (a) => {
|
|
1165
1165
|
const b = isFunction(f) ? f(a) : f
|
|
1166
1166
|
return isEither(b) ? b : right(b)
|
|
@@ -1176,15 +1176,15 @@ export const zipWith: {
|
|
|
1176
1176
|
* @category zipping
|
|
1177
1177
|
* @since 2.0.0
|
|
1178
1178
|
*/
|
|
1179
|
-
<
|
|
1179
|
+
<A2, E2, A, B>(that: Either<A2, E2>, f: (right: A, right2: A2) => B): <E>(self: Either<A, E>) => Either<B, E2 | E>
|
|
1180
1180
|
/**
|
|
1181
1181
|
* @category zipping
|
|
1182
1182
|
* @since 2.0.0
|
|
1183
1183
|
*/
|
|
1184
|
-
<
|
|
1184
|
+
<A, E, A2, E2, B>(self: Either<A, E>, that: Either<A2, E2>, f: (right: A, right2: A2) => B): Either<B, E | E2>
|
|
1185
1185
|
} = dual(
|
|
1186
1186
|
3,
|
|
1187
|
-
<
|
|
1187
|
+
<A, E, A2, E2, B>(self: Either<A, E>, that: Either<A2, E2>, f: (right: A, right2: A2) => B): Either<B, E | E2> =>
|
|
1188
1188
|
flatMap(self, (r) => map(that, (r2) => f(r, r2)))
|
|
1189
1189
|
)
|
|
1190
1190
|
|
|
@@ -1197,15 +1197,15 @@ export const ap: {
|
|
|
1197
1197
|
* @category combining
|
|
1198
1198
|
* @since 2.0.0
|
|
1199
1199
|
*/
|
|
1200
|
-
<
|
|
1200
|
+
<A, E2>(that: Either<A, E2>): <A2, E>(self: Either<(right: A) => A2, E>) => Either<A2, E | E2>
|
|
1201
1201
|
/**
|
|
1202
1202
|
* @category combining
|
|
1203
1203
|
* @since 2.0.0
|
|
1204
1204
|
*/
|
|
1205
|
-
<
|
|
1205
|
+
<A, A2, E, E2>(self: Either<(right: A) => A2, E>, that: Either<A, E2>): Either<A2, E | E2>
|
|
1206
1206
|
} = dual(
|
|
1207
1207
|
2,
|
|
1208
|
-
<
|
|
1208
|
+
<A, E, A2, E2>(self: Either<(right: A) => A2, E>, that: Either<A, E2>): Either<A2, E | E2> =>
|
|
1209
1209
|
zipWith(self, that, (f, a) => f(a))
|
|
1210
1210
|
)
|
|
1211
1211
|
|
|
@@ -1233,13 +1233,13 @@ export const ap: {
|
|
|
1233
1233
|
export const all: <const I extends Iterable<Either<any, any>> | Record<string, Either<any, any>>>(
|
|
1234
1234
|
input: I
|
|
1235
1235
|
) => [I] extends [ReadonlyArray<Either<any, any>>] ? Either<
|
|
1236
|
-
{ -readonly [K in keyof I]: [I[K]] extends [Either<infer
|
|
1237
|
-
I[number] extends never ? never : [I[number]] extends [Either<any, infer
|
|
1236
|
+
{ -readonly [K in keyof I]: [I[K]] extends [Either<infer A, any>] ? A : never },
|
|
1237
|
+
I[number] extends never ? never : [I[number]] extends [Either<any, infer E>] ? E : never
|
|
1238
1238
|
>
|
|
1239
|
-
: [I] extends [Iterable<Either<infer
|
|
1239
|
+
: [I] extends [Iterable<Either<infer A, infer E>>] ? Either<Array<A>, E>
|
|
1240
1240
|
: Either<
|
|
1241
|
-
{ -readonly [K in keyof I]: [I[K]] extends [Either<infer
|
|
1242
|
-
I[keyof I] extends never ? never : [I[keyof I]] extends [Either<any, infer
|
|
1241
|
+
{ -readonly [K in keyof I]: [I[K]] extends [Either<infer A, any>] ? A : never },
|
|
1242
|
+
I[keyof I] extends never ? never : [I[keyof I]] extends [Either<any, infer E>] ? E : never
|
|
1243
1243
|
> = (
|
|
1244
1244
|
input: Iterable<Either<any, any>> | Record<string, Either<any, any>>
|
|
1245
1245
|
): Either<any, any> => {
|
|
@@ -1272,7 +1272,7 @@ export const all: <const I extends Iterable<Either<any, any>> | Record<string, E
|
|
|
1272
1272
|
* @since 2.0.0
|
|
1273
1273
|
* @category mapping
|
|
1274
1274
|
*/
|
|
1275
|
-
export const flip = <
|
|
1275
|
+
export const flip = <A, E>(self: Either<A, E>): Either<E, A> => isLeft(self) ? right(self.left) : left(self.right)
|
|
1276
1276
|
|
|
1277
1277
|
const adapter = Gen.adapter<EitherTypeLambda>()
|
|
1278
1278
|
|
|
@@ -1396,7 +1396,7 @@ export const bind: {
|
|
|
1396
1396
|
* @category do notation
|
|
1397
1397
|
* @since 2.0.0
|
|
1398
1398
|
*/
|
|
1399
|
-
<N extends string, A extends object, B,
|
|
1399
|
+
<N extends string, A extends object, B, E2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Either<B, E2>): <E>(self: Either<A, E>) => Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, E | E2>
|
|
1400
1400
|
/**
|
|
1401
1401
|
* The "do simulation" in Effect allows you to write code in a more declarative style, similar to the "do notation" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.
|
|
1402
1402
|
*
|
|
@@ -1428,11 +1428,11 @@ export const bind: {
|
|
|
1428
1428
|
* @category do notation
|
|
1429
1429
|
* @since 2.0.0
|
|
1430
1430
|
*/
|
|
1431
|
-
<A extends object,
|
|
1432
|
-
self: Either<A,
|
|
1431
|
+
<A extends object, E, N extends string, B, E2>(
|
|
1432
|
+
self: Either<A, E>,
|
|
1433
1433
|
name: Exclude<N, keyof A>,
|
|
1434
|
-
f: (a: NoInfer<A>) => Either<B,
|
|
1435
|
-
): Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B },
|
|
1434
|
+
f: (a: NoInfer<A>) => Either<B, E2>
|
|
1435
|
+
): Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, E | E2>
|
|
1436
1436
|
} = doNotation.bind<EitherTypeLambda>(map, flatMap)
|
|
1437
1437
|
|
|
1438
1438
|
/**
|
|
@@ -1498,7 +1498,7 @@ export const bindTo: {
|
|
|
1498
1498
|
* @category do notation
|
|
1499
1499
|
* @since 2.0.0
|
|
1500
1500
|
*/
|
|
1501
|
-
<N extends string>(name: N): <
|
|
1501
|
+
<N extends string>(name: N): <A, E>(self: Either<A, E>) => Either<{ [K in N]: A }, E>
|
|
1502
1502
|
/**
|
|
1503
1503
|
* The "do simulation" in Effect allows you to write code in a more declarative style, similar to the "do notation" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.
|
|
1504
1504
|
*
|
|
@@ -1530,19 +1530,19 @@ export const bindTo: {
|
|
|
1530
1530
|
* @category do notation
|
|
1531
1531
|
* @since 2.0.0
|
|
1532
1532
|
*/
|
|
1533
|
-
<
|
|
1533
|
+
<A, E, N extends string>(self: Either<A, E>, name: N): Either<{ [K in N]: A }, E>
|
|
1534
1534
|
} = doNotation.bindTo<EitherTypeLambda>(map)
|
|
1535
1535
|
|
|
1536
1536
|
const let_: {
|
|
1537
|
-
<N extends string,
|
|
1538
|
-
name: Exclude<N, keyof
|
|
1539
|
-
f: (r: NoInfer<
|
|
1540
|
-
): <
|
|
1541
|
-
<
|
|
1542
|
-
self: Either<
|
|
1543
|
-
name: Exclude<N, keyof
|
|
1544
|
-
f: (r: NoInfer<
|
|
1545
|
-
): Either<{ [K in N | keyof
|
|
1537
|
+
<N extends string, A extends object, B>(
|
|
1538
|
+
name: Exclude<N, keyof A>,
|
|
1539
|
+
f: (r: NoInfer<A>) => B
|
|
1540
|
+
): <E>(self: Either<A, E>) => Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, E>
|
|
1541
|
+
<A extends object, E, N extends string, B>(
|
|
1542
|
+
self: Either<A, E>,
|
|
1543
|
+
name: Exclude<N, keyof A>,
|
|
1544
|
+
f: (r: NoInfer<A>) => B
|
|
1545
|
+
): Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, E>
|
|
1546
1546
|
} = doNotation.let_<EitherTypeLambda>(map)
|
|
1547
1547
|
|
|
1548
1548
|
export {
|