effect 3.1.0 → 3.1.2
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/Array.js +10 -13
- package/dist/cjs/Array.js.map +1 -1
- package/dist/cjs/BigDecimal.js +14 -17
- package/dist/cjs/BigDecimal.js.map +1 -1
- package/dist/cjs/BigInt.js +41 -46
- package/dist/cjs/BigInt.js.map +1 -1
- package/dist/cjs/Boolean.js +13 -13
- package/dist/cjs/Brand.js +2 -2
- package/dist/cjs/Chunk.js +3 -3
- package/dist/cjs/Context.js +15 -20
- package/dist/cjs/Context.js.map +1 -1
- package/dist/cjs/Cron.js +3 -6
- package/dist/cjs/Cron.js.map +1 -1
- package/dist/cjs/Data.js +8 -13
- package/dist/cjs/Data.js.map +1 -1
- package/dist/cjs/Duration.js +1 -1
- package/dist/cjs/Effect.js +77 -9
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/Either.js +117 -59
- package/dist/cjs/Either.js.map +1 -1
- package/dist/cjs/Equal.js +26 -4
- package/dist/cjs/Equal.js.map +1 -1
- package/dist/cjs/FiberHandle.js.map +1 -1
- package/dist/cjs/FiberMap.js.map +1 -1
- package/dist/cjs/FiberSet.js.map +1 -1
- package/dist/cjs/Function.js +2 -2
- package/dist/cjs/Function.js.map +1 -1
- package/dist/cjs/Hash.js +29 -12
- package/dist/cjs/Hash.js.map +1 -1
- package/dist/cjs/Iterable.js +10 -13
- package/dist/cjs/Iterable.js.map +1 -1
- package/dist/cjs/List.js +2 -2
- package/dist/cjs/Metric.js +5 -7
- package/dist/cjs/Metric.js.map +1 -1
- package/dist/cjs/Number.js +20 -21
- package/dist/cjs/Number.js.map +1 -1
- package/dist/cjs/Option.js +223 -164
- package/dist/cjs/Option.js.map +1 -1
- package/dist/cjs/Order.js +1 -2
- package/dist/cjs/Order.js.map +1 -1
- package/dist/cjs/Ordering.js +2 -2
- package/dist/cjs/Predicate.js +9 -12
- package/dist/cjs/Predicate.js.map +1 -1
- package/dist/cjs/Readable.js.map +1 -1
- package/dist/cjs/Record.js +35 -47
- package/dist/cjs/Record.js.map +1 -1
- package/dist/cjs/RegExp.js +1 -1
- package/dist/cjs/Request.js +2 -2
- package/dist/cjs/Request.js.map +1 -1
- package/dist/cjs/Stream.js +82 -4
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/String.js +81 -111
- package/dist/cjs/String.js.map +1 -1
- package/dist/cjs/Struct.js +13 -19
- package/dist/cjs/Struct.js.map +1 -1
- package/dist/cjs/Subscribable.js.map +1 -1
- package/dist/cjs/Symbol.js +3 -3
- package/dist/cjs/TestAnnotation.js.map +1 -1
- package/dist/cjs/TestAnnotationMap.js.map +1 -1
- package/dist/cjs/TestAnnotations.js.map +1 -1
- package/dist/cjs/TestClock.js.map +1 -1
- package/dist/cjs/TestLive.js.map +1 -1
- package/dist/cjs/TestSized.js.map +1 -1
- package/dist/cjs/Trie.js +28 -44
- package/dist/cjs/Trie.js.map +1 -1
- package/dist/cjs/Utils.js +35 -1
- package/dist/cjs/Utils.js.map +1 -1
- package/dist/cjs/internal/core-effect.js +4 -11
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/core.js +16 -4
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/doNotation.js +23 -0
- package/dist/cjs/internal/doNotation.js.map +1 -0
- package/dist/cjs/internal/groupBy.js.map +1 -1
- package/dist/cjs/internal/stream.js +3 -7
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Array.d.ts +10 -13
- package/dist/dts/Array.d.ts.map +1 -1
- package/dist/dts/BigDecimal.d.ts +14 -17
- package/dist/dts/BigDecimal.d.ts.map +1 -1
- package/dist/dts/BigInt.d.ts +41 -46
- package/dist/dts/BigInt.d.ts.map +1 -1
- package/dist/dts/Boolean.d.ts +13 -13
- package/dist/dts/Brand.d.ts +3 -3
- package/dist/dts/Chunk.d.ts +3 -3
- package/dist/dts/Context.d.ts +15 -20
- package/dist/dts/Context.d.ts.map +1 -1
- package/dist/dts/Cron.d.ts +3 -6
- package/dist/dts/Cron.d.ts.map +1 -1
- package/dist/dts/Data.d.ts +10 -16
- package/dist/dts/Data.d.ts.map +1 -1
- package/dist/dts/Duration.d.ts +1 -1
- package/dist/dts/Effect.d.ts +120 -26
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/Either.d.ts +155 -64
- package/dist/dts/Either.d.ts.map +1 -1
- package/dist/dts/Equal.d.ts.map +1 -1
- package/dist/dts/FiberHandle.d.ts.map +1 -1
- package/dist/dts/FiberMap.d.ts.map +1 -1
- package/dist/dts/FiberSet.d.ts.map +1 -1
- package/dist/dts/Function.d.ts +4 -2
- package/dist/dts/Function.d.ts.map +1 -1
- package/dist/dts/Hash.d.ts.map +1 -1
- package/dist/dts/HashMap.d.ts +2 -2
- package/dist/dts/Iterable.d.ts +10 -13
- package/dist/dts/Iterable.d.ts.map +1 -1
- package/dist/dts/List.d.ts +2 -2
- package/dist/dts/Metric.d.ts +5 -7
- package/dist/dts/Metric.d.ts.map +1 -1
- package/dist/dts/Number.d.ts +20 -21
- package/dist/dts/Number.d.ts.map +1 -1
- package/dist/dts/Option.d.ts +245 -155
- package/dist/dts/Option.d.ts.map +1 -1
- package/dist/dts/Order.d.ts +1 -2
- package/dist/dts/Order.d.ts.map +1 -1
- package/dist/dts/Ordering.d.ts +2 -2
- package/dist/dts/Predicate.d.ts +9 -12
- package/dist/dts/Predicate.d.ts.map +1 -1
- package/dist/dts/Readable.d.ts.map +1 -1
- package/dist/dts/Record.d.ts +35 -47
- package/dist/dts/Record.d.ts.map +1 -1
- package/dist/dts/RegExp.d.ts +1 -1
- package/dist/dts/Request.d.ts +2 -2
- package/dist/dts/Request.d.ts.map +1 -1
- package/dist/dts/Stream.d.ts +136 -31
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/String.d.ts +81 -111
- package/dist/dts/String.d.ts.map +1 -1
- package/dist/dts/Struct.d.ts +13 -19
- package/dist/dts/Struct.d.ts.map +1 -1
- package/dist/dts/Subscribable.d.ts.map +1 -1
- package/dist/dts/Symbol.d.ts +3 -3
- package/dist/dts/TestAnnotation.d.ts.map +1 -1
- package/dist/dts/TestAnnotationMap.d.ts.map +1 -1
- package/dist/dts/TestAnnotations.d.ts.map +1 -1
- package/dist/dts/TestClock.d.ts +1 -5
- package/dist/dts/TestClock.d.ts.map +1 -1
- package/dist/dts/TestLive.d.ts.map +1 -1
- package/dist/dts/TestSized.d.ts.map +1 -1
- package/dist/dts/Trie.d.ts +28 -44
- package/dist/dts/Trie.d.ts.map +1 -1
- package/dist/dts/Types.d.ts +10 -10
- package/dist/dts/Utils.d.ts +19 -0
- package/dist/dts/Utils.d.ts.map +1 -1
- package/dist/dts/internal/core.d.ts.map +1 -1
- package/dist/dts/internal/doNotation.d.ts +2 -0
- package/dist/dts/internal/doNotation.d.ts.map +1 -0
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/Array.js +10 -13
- package/dist/esm/Array.js.map +1 -1
- package/dist/esm/BigDecimal.js +14 -17
- package/dist/esm/BigDecimal.js.map +1 -1
- package/dist/esm/BigInt.js +41 -46
- package/dist/esm/BigInt.js.map +1 -1
- package/dist/esm/Boolean.js +13 -13
- package/dist/esm/Brand.js +2 -2
- package/dist/esm/Chunk.js +3 -3
- package/dist/esm/Context.js +15 -20
- package/dist/esm/Context.js.map +1 -1
- package/dist/esm/Cron.js +3 -6
- package/dist/esm/Cron.js.map +1 -1
- package/dist/esm/Data.js +9 -15
- package/dist/esm/Data.js.map +1 -1
- package/dist/esm/Duration.js +1 -1
- package/dist/esm/Effect.js +101 -11
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/Either.js +141 -61
- package/dist/esm/Either.js.map +1 -1
- package/dist/esm/Equal.js +26 -4
- package/dist/esm/Equal.js.map +1 -1
- package/dist/esm/FiberHandle.js.map +1 -1
- package/dist/esm/FiberMap.js.map +1 -1
- package/dist/esm/FiberSet.js.map +1 -1
- package/dist/esm/Function.js +2 -2
- package/dist/esm/Function.js.map +1 -1
- package/dist/esm/Hash.js +30 -13
- package/dist/esm/Hash.js.map +1 -1
- package/dist/esm/Iterable.js +10 -13
- package/dist/esm/Iterable.js.map +1 -1
- package/dist/esm/List.js +2 -2
- package/dist/esm/Metric.js +5 -7
- package/dist/esm/Metric.js.map +1 -1
- package/dist/esm/Number.js +20 -21
- package/dist/esm/Number.js.map +1 -1
- package/dist/esm/Option.js +249 -164
- package/dist/esm/Option.js.map +1 -1
- package/dist/esm/Order.js +1 -2
- package/dist/esm/Order.js.map +1 -1
- package/dist/esm/Ordering.js +2 -2
- package/dist/esm/Predicate.js +9 -12
- package/dist/esm/Predicate.js.map +1 -1
- package/dist/esm/Readable.js.map +1 -1
- package/dist/esm/Record.js +35 -47
- package/dist/esm/Record.js.map +1 -1
- package/dist/esm/RegExp.js +1 -1
- package/dist/esm/Request.js +2 -2
- package/dist/esm/Request.js.map +1 -1
- package/dist/esm/Stream.js +107 -6
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/String.js +81 -111
- package/dist/esm/String.js.map +1 -1
- package/dist/esm/Struct.js +13 -19
- package/dist/esm/Struct.js.map +1 -1
- package/dist/esm/Subscribable.js.map +1 -1
- package/dist/esm/Symbol.js +3 -3
- package/dist/esm/TestAnnotation.js.map +1 -1
- package/dist/esm/TestAnnotationMap.js.map +1 -1
- package/dist/esm/TestAnnotations.js.map +1 -1
- package/dist/esm/TestClock.js.map +1 -1
- package/dist/esm/TestLive.js.map +1 -1
- package/dist/esm/TestSized.js.map +1 -1
- package/dist/esm/Trie.js +28 -44
- package/dist/esm/Trie.js.map +1 -1
- package/dist/esm/Utils.js +33 -0
- package/dist/esm/Utils.js.map +1 -1
- package/dist/esm/internal/core-effect.js +4 -11
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/core.js +16 -4
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/doNotation.js +14 -0
- package/dist/esm/internal/doNotation.js.map +1 -0
- package/dist/esm/internal/groupBy.js.map +1 -1
- package/dist/esm/internal/stream.js +3 -7
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Array.ts +10 -13
- package/src/BigDecimal.ts +14 -17
- package/src/BigInt.ts +41 -46
- package/src/Boolean.ts +13 -13
- package/src/Brand.ts +3 -3
- package/src/Chunk.ts +3 -3
- package/src/Context.ts +15 -20
- package/src/Cron.ts +3 -6
- package/src/Data.ts +10 -16
- package/src/Duration.ts +1 -1
- package/src/Effect.ts +122 -32
- package/src/Either.ts +161 -94
- package/src/Equal.ts +30 -9
- package/src/FiberHandle.ts +1 -1
- package/src/FiberMap.ts +1 -1
- package/src/FiberSet.ts +1 -1
- package/src/Function.ts +4 -2
- package/src/Hash.ts +30 -13
- package/src/HashMap.ts +2 -2
- package/src/Iterable.ts +10 -13
- package/src/List.ts +2 -2
- package/src/Metric.ts +5 -7
- package/src/Number.ts +20 -21
- package/src/Option.ts +250 -172
- package/src/Order.ts +1 -2
- package/src/Ordering.ts +2 -2
- package/src/Predicate.ts +9 -12
- package/src/Readable.ts +1 -1
- package/src/Record.ts +35 -47
- package/src/RegExp.ts +1 -1
- package/src/Request.ts +3 -3
- package/src/Stream.ts +137 -36
- package/src/String.ts +81 -111
- package/src/Struct.ts +13 -19
- package/src/Subscribable.ts +1 -1
- package/src/Symbol.ts +3 -3
- package/src/TestAnnotation.ts +1 -1
- package/src/TestAnnotationMap.ts +1 -1
- package/src/TestAnnotations.ts +1 -1
- package/src/TestClock.ts +1 -5
- package/src/TestLive.ts +1 -1
- package/src/TestSized.ts +1 -1
- package/src/Trie.ts +28 -44
- package/src/Types.ts +10 -10
- package/src/Utils.ts +40 -2
- package/src/internal/core-effect.ts +29 -45
- package/src/internal/core.ts +20 -4
- package/src/internal/doNotation.ts +77 -0
- package/src/internal/groupBy.ts +16 -16
- package/src/internal/stream.ts +34 -58
- package/src/internal/version.ts +1 -1
package/src/Either.ts
CHANGED
|
@@ -7,12 +7,13 @@ import type { LazyArg } from "./Function.js"
|
|
|
7
7
|
import { constNull, constUndefined, dual, identity } from "./Function.js"
|
|
8
8
|
import type { TypeLambda } from "./HKT.js"
|
|
9
9
|
import type { Inspectable } from "./Inspectable.js"
|
|
10
|
+
import * as doNotation from "./internal/doNotation.js"
|
|
10
11
|
import * as either from "./internal/either.js"
|
|
11
12
|
import type { Option } from "./Option.js"
|
|
12
13
|
import type { Pipeable } from "./Pipeable.js"
|
|
13
14
|
import type { Predicate, Refinement } from "./Predicate.js"
|
|
14
15
|
import { isFunction } from "./Predicate.js"
|
|
15
|
-
import type { Covariant,
|
|
16
|
+
import type { Covariant, NoInfer, NotFunction } from "./Types.js"
|
|
16
17
|
import type * as Unify from "./Unify.js"
|
|
17
18
|
import * as Gen from "./Utils.js"
|
|
18
19
|
|
|
@@ -129,7 +130,7 @@ export const left: <L>(left: L) => Either<never, L> = either.left
|
|
|
129
130
|
* the provided default as a `Left`.
|
|
130
131
|
*
|
|
131
132
|
* @example
|
|
132
|
-
* import
|
|
133
|
+
* import { Either } from "effect"
|
|
133
134
|
*
|
|
134
135
|
* assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))
|
|
135
136
|
* assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))
|
|
@@ -148,8 +149,7 @@ export const fromNullable: {
|
|
|
148
149
|
|
|
149
150
|
/**
|
|
150
151
|
* @example
|
|
151
|
-
* import
|
|
152
|
-
* import * as Option from 'effect/Option'
|
|
152
|
+
* import { Either, Option } from "effect"
|
|
153
153
|
*
|
|
154
154
|
* assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))
|
|
155
155
|
* assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))
|
|
@@ -208,11 +208,11 @@ export {
|
|
|
208
208
|
* @param input - The value to test.
|
|
209
209
|
*
|
|
210
210
|
* @example
|
|
211
|
-
* import {
|
|
211
|
+
* import { Either } from "effect"
|
|
212
212
|
*
|
|
213
|
-
* assert.deepStrictEqual(isEither(right(1)), true)
|
|
214
|
-
* assert.deepStrictEqual(isEither(left("a")), true)
|
|
215
|
-
* assert.deepStrictEqual(isEither({ right: 1 }), false)
|
|
213
|
+
* assert.deepStrictEqual(Either.isEither(Either.right(1)), true)
|
|
214
|
+
* assert.deepStrictEqual(Either.isEither(Either.left("a")), true)
|
|
215
|
+
* assert.deepStrictEqual(Either.isEither({ right: 1 }), false)
|
|
216
216
|
*
|
|
217
217
|
* @category guards
|
|
218
218
|
* @since 2.0.0
|
|
@@ -225,10 +225,10 @@ export const isEither: (input: unknown) => input is Either<unknown, unknown> = e
|
|
|
225
225
|
* @param self - The `Either` to check.
|
|
226
226
|
*
|
|
227
227
|
* @example
|
|
228
|
-
* import {
|
|
228
|
+
* import { Either } from "effect"
|
|
229
229
|
*
|
|
230
|
-
* assert.deepStrictEqual(isLeft(right(1)), false)
|
|
231
|
-
* assert.deepStrictEqual(isLeft(left("a")), true)
|
|
230
|
+
* assert.deepStrictEqual(Either.isLeft(Either.right(1)), false)
|
|
231
|
+
* assert.deepStrictEqual(Either.isLeft(Either.left("a")), true)
|
|
232
232
|
*
|
|
233
233
|
* @category guards
|
|
234
234
|
* @since 2.0.0
|
|
@@ -241,10 +241,10 @@ export const isLeft: <R, L>(self: Either<R, L>) => self is Left<L, R> = either.i
|
|
|
241
241
|
* @param self - The `Either` to check.
|
|
242
242
|
*
|
|
243
243
|
* @example
|
|
244
|
-
* import {
|
|
244
|
+
* import { Either } from "effect"
|
|
245
245
|
*
|
|
246
|
-
* assert.deepStrictEqual(isRight(right(1)), true)
|
|
247
|
-
* assert.deepStrictEqual(isRight(left("a")), false)
|
|
246
|
+
* assert.deepStrictEqual(Either.isRight(Either.right(1)), true)
|
|
247
|
+
* assert.deepStrictEqual(Either.isRight(Either.left("a")), false)
|
|
248
248
|
*
|
|
249
249
|
* @category guards
|
|
250
250
|
* @since 2.0.0
|
|
@@ -257,11 +257,10 @@ export const isRight: <R, L>(self: Either<R, L>) => self is Right<L, R> = either
|
|
|
257
257
|
* Alias of {@link toOption}.
|
|
258
258
|
*
|
|
259
259
|
* @example
|
|
260
|
-
* import
|
|
261
|
-
* import * as E from 'effect/Either'
|
|
260
|
+
* import { Either, Option } from "effect"
|
|
262
261
|
*
|
|
263
|
-
* assert.deepStrictEqual(
|
|
264
|
-
* assert.deepStrictEqual(
|
|
262
|
+
* assert.deepStrictEqual(Either.getRight(Either.right('ok')), Option.some('ok'))
|
|
263
|
+
* assert.deepStrictEqual(Either.getRight(Either.left('err')), Option.none())
|
|
265
264
|
*
|
|
266
265
|
* @category getters
|
|
267
266
|
* @since 2.0.0
|
|
@@ -272,11 +271,10 @@ export const getRight: <R, L>(self: Either<R, L>) => Option<R> = either.getRight
|
|
|
272
271
|
* Converts a `Either` to an `Option` discarding the value.
|
|
273
272
|
*
|
|
274
273
|
* @example
|
|
275
|
-
* import
|
|
276
|
-
* import * as E from 'effect/Either'
|
|
274
|
+
* import { Either, Option } from "effect"
|
|
277
275
|
*
|
|
278
|
-
* assert.deepStrictEqual(
|
|
279
|
-
* assert.deepStrictEqual(
|
|
276
|
+
* assert.deepStrictEqual(Either.getLeft(Either.right('ok')), Option.none())
|
|
277
|
+
* assert.deepStrictEqual(Either.getLeft(Either.left('err')), Option.some('err'))
|
|
280
278
|
*
|
|
281
279
|
* @category getters
|
|
282
280
|
* @since 2.0.0
|
|
@@ -360,16 +358,15 @@ export const map: {
|
|
|
360
358
|
* if the value is a `Right` the inner value is applied to the `onRight` function.
|
|
361
359
|
*
|
|
362
360
|
* @example
|
|
363
|
-
* import
|
|
364
|
-
* import { pipe } from 'effect/Function'
|
|
361
|
+
* import { pipe, Either } from "effect"
|
|
365
362
|
*
|
|
366
363
|
* const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`
|
|
367
364
|
*
|
|
368
365
|
* const onRight = (value: number): string => `Ok: ${value}`
|
|
369
366
|
*
|
|
370
|
-
* assert.deepStrictEqual(pipe(
|
|
367
|
+
* assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')
|
|
371
368
|
* assert.deepStrictEqual(
|
|
372
|
-
* pipe(
|
|
369
|
+
* pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),
|
|
373
370
|
* 'strings: string 1, string 2'
|
|
374
371
|
* )
|
|
375
372
|
*
|
|
@@ -398,24 +395,23 @@ export const match: {
|
|
|
398
395
|
* If the predicate fails, set the left value with the result of the provided function.
|
|
399
396
|
*
|
|
400
397
|
* @example
|
|
401
|
-
* import
|
|
402
|
-
* import { pipe } from 'effect/Function'
|
|
398
|
+
* import { pipe, Either } from "effect"
|
|
403
399
|
*
|
|
404
400
|
* const isPositive = (n: number): boolean => n > 0
|
|
405
401
|
*
|
|
406
402
|
* assert.deepStrictEqual(
|
|
407
403
|
* pipe(
|
|
408
|
-
*
|
|
409
|
-
*
|
|
404
|
+
* Either.right(1),
|
|
405
|
+
* Either.filterOrLeft(isPositive, n => `${n} is not positive`)
|
|
410
406
|
* ),
|
|
411
|
-
*
|
|
407
|
+
* Either.right(1)
|
|
412
408
|
* )
|
|
413
409
|
* assert.deepStrictEqual(
|
|
414
410
|
* pipe(
|
|
415
|
-
*
|
|
416
|
-
*
|
|
411
|
+
* Either.right(0),
|
|
412
|
+
* Either.filterOrLeft(isPositive, n => `${n} is not positive`)
|
|
417
413
|
* ),
|
|
418
|
-
*
|
|
414
|
+
* Either.left("0 is not positive")
|
|
419
415
|
* )
|
|
420
416
|
*
|
|
421
417
|
* @since 2.0.0
|
|
@@ -455,7 +451,7 @@ export const merge: <R, L>(self: Either<R, L>) => L | R = match({
|
|
|
455
451
|
* Returns the wrapped value if it's a `Right` or a default value if is a `Left`.
|
|
456
452
|
*
|
|
457
453
|
* @example
|
|
458
|
-
* import
|
|
454
|
+
* import { Either } from "effect"
|
|
459
455
|
*
|
|
460
456
|
* assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + "!"), 1)
|
|
461
457
|
* assert.deepStrictEqual(Either.getOrElse(Either.left("not a number"), (error) => error + "!"), "not a number!")
|
|
@@ -473,7 +469,7 @@ export const getOrElse: {
|
|
|
473
469
|
|
|
474
470
|
/**
|
|
475
471
|
* @example
|
|
476
|
-
* import
|
|
472
|
+
* import { Either } from "effect"
|
|
477
473
|
*
|
|
478
474
|
* assert.deepStrictEqual(Either.getOrNull(Either.right(1)), 1)
|
|
479
475
|
* assert.deepStrictEqual(Either.getOrNull(Either.left("a")), null)
|
|
@@ -485,7 +481,7 @@ export const getOrNull: <R, L>(self: Either<R, L>) => R | null = getOrElse(const
|
|
|
485
481
|
|
|
486
482
|
/**
|
|
487
483
|
* @example
|
|
488
|
-
* import
|
|
484
|
+
* import { Either } from "effect"
|
|
489
485
|
*
|
|
490
486
|
* assert.deepStrictEqual(Either.getOrUndefined(Either.right(1)), 1)
|
|
491
487
|
* assert.deepStrictEqual(Either.getOrUndefined(Either.left("a")), undefined)
|
|
@@ -504,13 +500,13 @@ export const getOrUndefined: <R, L>(self: Either<R, L>) => R | undefined = getOr
|
|
|
504
500
|
* @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown.
|
|
505
501
|
*
|
|
506
502
|
* @example
|
|
507
|
-
* import
|
|
503
|
+
* import { Either } from "effect"
|
|
508
504
|
*
|
|
509
505
|
* assert.deepStrictEqual(
|
|
510
|
-
*
|
|
506
|
+
* Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),
|
|
511
507
|
* 1
|
|
512
508
|
* )
|
|
513
|
-
* assert.throws(() =>
|
|
509
|
+
* assert.throws(() => Either.getOrThrowWith(Either.left("error"), () => new Error('Unexpected Left')))
|
|
514
510
|
*
|
|
515
511
|
* @category getters
|
|
516
512
|
* @since 2.0.0
|
|
@@ -534,10 +530,10 @@ export const getOrThrowWith: {
|
|
|
534
530
|
* @throws `Error("getOrThrow called on a Left")`
|
|
535
531
|
*
|
|
536
532
|
* @example
|
|
537
|
-
* import
|
|
533
|
+
* import { Either } from "effect"
|
|
538
534
|
*
|
|
539
|
-
* assert.deepStrictEqual(
|
|
540
|
-
* assert.throws(() =>
|
|
535
|
+
* assert.deepStrictEqual(Either.getOrThrow(Either.right(1)), 1)
|
|
536
|
+
* assert.throws(() => Either.getOrThrow(Either.left("error")))
|
|
541
537
|
*
|
|
542
538
|
* @category getters
|
|
543
539
|
* @since 2.0.0
|
|
@@ -644,7 +640,7 @@ export const ap: {
|
|
|
644
640
|
* @param fields - the struct of `Either`s to be sequenced.
|
|
645
641
|
*
|
|
646
642
|
* @example
|
|
647
|
-
* import
|
|
643
|
+
* import { Either } from "effect"
|
|
648
644
|
*
|
|
649
645
|
* assert.deepStrictEqual(Either.all([Either.right(1), Either.right(2)]), Either.right([1, 2]))
|
|
650
646
|
* assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.right("hello") }), Either.right({ right: 1, b: "hello" }))
|
|
@@ -742,77 +738,148 @@ export const gen: Gen.Gen<EitherTypeLambda, Gen.Adapter<EitherTypeLambda>> = (f)
|
|
|
742
738
|
// -------------------------------------------------------------------------------------
|
|
743
739
|
|
|
744
740
|
/**
|
|
745
|
-
*
|
|
741
|
+
* The "do simulation" in 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`.
|
|
742
|
+
*
|
|
743
|
+
* Here's how the do simulation works:
|
|
744
|
+
*
|
|
745
|
+
* 1. Start the do simulation using the `Do` value
|
|
746
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values
|
|
747
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
748
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
749
|
+
*
|
|
750
|
+
* @see {@link bind}
|
|
751
|
+
* @see {@link bindTo}
|
|
752
|
+
* @see {@link let_ let}
|
|
753
|
+
*
|
|
754
|
+
* @example
|
|
755
|
+
* import { Either, pipe } from "effect"
|
|
756
|
+
*
|
|
757
|
+
* const result = pipe(
|
|
758
|
+
* Either.Do,
|
|
759
|
+
* Either.bind("x", () => Either.right(2)),
|
|
760
|
+
* Either.bind("y", () => Either.right(3)),
|
|
761
|
+
* Either.let("sum", ({ x, y }) => x + y)
|
|
762
|
+
* )
|
|
763
|
+
* assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))
|
|
764
|
+
*
|
|
746
765
|
* @category do notation
|
|
766
|
+
* @since 2.0.0
|
|
747
767
|
*/
|
|
748
768
|
export const Do: Either<{}> = right({})
|
|
749
769
|
|
|
750
770
|
/**
|
|
751
|
-
*
|
|
771
|
+
* The "do simulation" in 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`.
|
|
772
|
+
*
|
|
773
|
+
* Here's how the do simulation works:
|
|
774
|
+
*
|
|
775
|
+
* 1. Start the do simulation using the `Do` value
|
|
776
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values
|
|
777
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
778
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
779
|
+
*
|
|
780
|
+
* @see {@link Do}
|
|
781
|
+
* @see {@link bindTo}
|
|
782
|
+
* @see {@link let_ let}
|
|
783
|
+
*
|
|
784
|
+
* @example
|
|
785
|
+
* import { Either, pipe } from "effect"
|
|
786
|
+
*
|
|
787
|
+
* const result = pipe(
|
|
788
|
+
* Either.Do,
|
|
789
|
+
* Either.bind("x", () => Either.right(2)),
|
|
790
|
+
* Either.bind("y", () => Either.right(3)),
|
|
791
|
+
* Either.let("sum", ({ x, y }) => x + y)
|
|
792
|
+
* )
|
|
793
|
+
* assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))
|
|
752
794
|
*
|
|
753
|
-
* @since 2.4.0
|
|
754
795
|
* @category do notation
|
|
796
|
+
* @since 2.0.0
|
|
755
797
|
*/
|
|
756
798
|
export const bind: {
|
|
757
|
-
<N extends string,
|
|
758
|
-
|
|
759
|
-
f: (
|
|
760
|
-
): <
|
|
761
|
-
<
|
|
762
|
-
self: Either<
|
|
763
|
-
|
|
764
|
-
f: (
|
|
765
|
-
): Either<
|
|
766
|
-
} =
|
|
767
|
-
self: Either<K, E>,
|
|
768
|
-
tag: Exclude<N, keyof K>,
|
|
769
|
-
f: (_: K) => Either<A, E2>
|
|
770
|
-
): Either<MergeRecord<K, { [k in N]: A }>, E2 | E> =>
|
|
771
|
-
flatMap(self, (k) =>
|
|
772
|
-
map(
|
|
773
|
-
f(k),
|
|
774
|
-
(a): MergeRecord<K, { [k in N]: A }> => ({ ...k, [tag]: a } as any)
|
|
775
|
-
)))
|
|
799
|
+
<N extends string, A extends object, B, L2>(
|
|
800
|
+
name: Exclude<N, keyof A>,
|
|
801
|
+
f: (a: A) => Either<B, L2>
|
|
802
|
+
): <L1>(self: Either<A, L1>) => Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>
|
|
803
|
+
<A extends object, L1, N extends string, B, L2>(
|
|
804
|
+
self: Either<A, L1>,
|
|
805
|
+
name: Exclude<N, keyof A>,
|
|
806
|
+
f: (a: A) => Either<B, L2>
|
|
807
|
+
): Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>
|
|
808
|
+
} = doNotation.bind<EitherTypeLambda>(map, flatMap)
|
|
776
809
|
|
|
777
810
|
/**
|
|
811
|
+
* The "do simulation" in 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`.
|
|
812
|
+
*
|
|
813
|
+
* Here's how the do simulation works:
|
|
814
|
+
*
|
|
815
|
+
* 1. Start the do simulation using the `Do` value
|
|
816
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values
|
|
817
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
818
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
819
|
+
*
|
|
820
|
+
* @see {@link Do}
|
|
821
|
+
* @see {@link bind}
|
|
822
|
+
* @see {@link let_ let}
|
|
823
|
+
*
|
|
824
|
+
* @example
|
|
825
|
+
* import { Either, pipe } from "effect"
|
|
826
|
+
*
|
|
827
|
+
* const result = pipe(
|
|
828
|
+
* Either.Do,
|
|
829
|
+
* Either.bind("x", () => Either.right(2)),
|
|
830
|
+
* Either.bind("y", () => Either.right(3)),
|
|
831
|
+
* Either.let("sum", ({ x, y }) => x + y)
|
|
832
|
+
* )
|
|
833
|
+
* assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))
|
|
834
|
+
*
|
|
778
835
|
* @category do notation
|
|
779
|
-
* @since 2.
|
|
836
|
+
* @since 2.0.0
|
|
780
837
|
*/
|
|
781
838
|
export const bindTo: {
|
|
782
|
-
<N extends string>(
|
|
783
|
-
<
|
|
784
|
-
} =
|
|
785
|
-
2,
|
|
786
|
-
<A, E, N extends string>(self: Either<A, E>, tag: N): Either<Record<N, A>, E> =>
|
|
787
|
-
map(self, (a) => ({ [tag]: a } as Record<N, A>))
|
|
788
|
-
)
|
|
839
|
+
<N extends string>(name: N): <R, L>(self: Either<R, L>) => Either<{ [K in N]: R }, L>
|
|
840
|
+
<R, L, N extends string>(self: Either<R, L>, name: N): Either<{ [K in N]: R }, L>
|
|
841
|
+
} = doNotation.bindTo<EitherTypeLambda>(map)
|
|
789
842
|
|
|
790
843
|
const let_: {
|
|
791
|
-
<N extends string,
|
|
792
|
-
|
|
793
|
-
f: (
|
|
794
|
-
): <
|
|
795
|
-
<
|
|
796
|
-
self: Either<
|
|
797
|
-
|
|
798
|
-
f: (
|
|
799
|
-
): Either<
|
|
800
|
-
} =
|
|
801
|
-
self: Either<K, E>,
|
|
802
|
-
tag: Exclude<N, keyof K>,
|
|
803
|
-
f: (_: K) => A
|
|
804
|
-
): Either<MergeRecord<K, { [k in N]: A }>, E> =>
|
|
805
|
-
map(
|
|
806
|
-
self,
|
|
807
|
-
(k): MergeRecord<K, { [k in N]: A }> => ({ ...k, [tag]: f(k) } as any)
|
|
808
|
-
))
|
|
844
|
+
<N extends string, R extends object, B>(
|
|
845
|
+
name: Exclude<N, keyof R>,
|
|
846
|
+
f: (r: R) => B
|
|
847
|
+
): <L>(self: Either<R, L>) => Either<{ [K in N | keyof R]: K extends keyof R ? R[K] : B }, L>
|
|
848
|
+
<R extends object, L, N extends string, B>(
|
|
849
|
+
self: Either<R, L>,
|
|
850
|
+
name: Exclude<N, keyof R>,
|
|
851
|
+
f: (r: R) => B
|
|
852
|
+
): Either<{ [K in N | keyof R]: K extends keyof R ? R[K] : B }, L>
|
|
853
|
+
} = doNotation.let_<EitherTypeLambda>(map)
|
|
809
854
|
|
|
810
855
|
export {
|
|
811
856
|
/**
|
|
812
|
-
*
|
|
857
|
+
* The "do simulation" in 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`.
|
|
858
|
+
*
|
|
859
|
+
* Here's how the do simulation works:
|
|
860
|
+
*
|
|
861
|
+
* 1. Start the do simulation using the `Do` value
|
|
862
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values
|
|
863
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
864
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
865
|
+
*
|
|
866
|
+
* @see {@link Do}
|
|
867
|
+
* @see {@link bindTo}
|
|
868
|
+
* @see {@link bind}
|
|
869
|
+
*
|
|
870
|
+
* @example
|
|
871
|
+
* import { Either, pipe } from "effect"
|
|
872
|
+
*
|
|
873
|
+
* const result = pipe(
|
|
874
|
+
* Either.Do,
|
|
875
|
+
* Either.bind("x", () => Either.right(2)),
|
|
876
|
+
* Either.bind("y", () => Either.right(3)),
|
|
877
|
+
* Either.let("sum", ({ x, y }) => x + y)
|
|
878
|
+
* )
|
|
879
|
+
* assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))
|
|
813
880
|
*
|
|
814
|
-
* @since 2.4.0
|
|
815
881
|
* @category do notation
|
|
882
|
+
* @since 2.0.0
|
|
816
883
|
*/
|
|
817
884
|
let_ as let
|
|
818
885
|
}
|
package/src/Equal.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import type { Equivalence } from "./Equivalence.js"
|
|
5
5
|
import * as Hash from "./Hash.js"
|
|
6
6
|
import { hasProperty } from "./Predicate.js"
|
|
7
|
+
import { structuralRegionState } from "./Utils.js"
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @since 2.0.0
|
|
@@ -32,7 +33,7 @@ export function equals(): any {
|
|
|
32
33
|
return compareBoth(arguments[0], arguments[1])
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
function compareBoth(self: unknown, that: unknown) {
|
|
36
|
+
function compareBoth(self: unknown, that: unknown): boolean {
|
|
36
37
|
if (self === that) {
|
|
37
38
|
return true
|
|
38
39
|
}
|
|
@@ -40,16 +41,36 @@ function compareBoth(self: unknown, that: unknown) {
|
|
|
40
41
|
if (selfType !== typeof that) {
|
|
41
42
|
return false
|
|
42
43
|
}
|
|
43
|
-
if (
|
|
44
|
-
(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
if (selfType === "object" || selfType === "function") {
|
|
45
|
+
if (self !== null && that !== null) {
|
|
46
|
+
if (isEqual(self) && isEqual(that)) {
|
|
47
|
+
return Hash.hash(self) === Hash.hash(that) && self[symbol](that)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (structuralRegionState.enabled) {
|
|
51
|
+
if (Array.isArray(self) && Array.isArray(that)) {
|
|
52
|
+
return self.length === that.length && self.every((v, i) => compareBoth(v, that[i]))
|
|
53
|
+
}
|
|
54
|
+
if (Object.getPrototypeOf(self) === Object.prototype && Object.getPrototypeOf(self) === Object.prototype) {
|
|
55
|
+
const keysSelf = Object.keys(self as any)
|
|
56
|
+
const keysThat = Object.keys(that as any)
|
|
57
|
+
if (keysSelf.length === keysThat.length) {
|
|
58
|
+
for (const key of keysSelf) {
|
|
59
|
+
// @ts-expect-error
|
|
60
|
+
if (!(key in that && compareBoth(self[key], that[key]))) {
|
|
61
|
+
return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false
|
|
50
68
|
}
|
|
51
69
|
}
|
|
52
|
-
|
|
70
|
+
|
|
71
|
+
return structuralRegionState.enabled && structuralRegionState.tester
|
|
72
|
+
? structuralRegionState.tester(self, that)
|
|
73
|
+
: false
|
|
53
74
|
}
|
|
54
75
|
|
|
55
76
|
/**
|
package/src/FiberHandle.ts
CHANGED
package/src/FiberMap.ts
CHANGED
package/src/FiberSet.ts
CHANGED
package/src/Function.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface FunctionTypeLambda extends TypeLambda {
|
|
|
17
17
|
* @param input - The value to test.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
|
-
* import { isFunction } from
|
|
20
|
+
* import { isFunction } from "effect/Predicate"
|
|
21
21
|
*
|
|
22
22
|
* assert.deepStrictEqual(isFunction(isFunction), true)
|
|
23
23
|
* assert.deepStrictEqual(isFunction("function"), false)
|
|
@@ -154,7 +154,7 @@ export const dual: {
|
|
|
154
154
|
*
|
|
155
155
|
* @example
|
|
156
156
|
* import { pipe, apply } from "effect/Function"
|
|
157
|
-
* import { length } from
|
|
157
|
+
* import { length } from "effect/String"
|
|
158
158
|
*
|
|
159
159
|
* assert.deepStrictEqual(pipe(length, apply("hello")), 5)
|
|
160
160
|
*
|
|
@@ -408,6 +408,8 @@ export const untupled = <A extends ReadonlyArray<unknown>, B>(f: (a: A) => B): (
|
|
|
408
408
|
*
|
|
409
409
|
* @example
|
|
410
410
|
* import { pipe } from "effect/Function"
|
|
411
|
+
* // Alternatively, you can use the following import syntax, as `pipe` is also conveniently exported from the `effect` entry point:
|
|
412
|
+
* // import { pipe } from "effect"
|
|
411
413
|
*
|
|
412
414
|
* const length = (s: string): number => s.length
|
|
413
415
|
* const double = (n: number): number => n * 2
|
package/src/Hash.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { pipe } from "./Function.js"
|
|
5
5
|
import { globalValue } from "./GlobalValue.js"
|
|
6
6
|
import { hasProperty } from "./Predicate.js"
|
|
7
|
-
import { PCGRandom } from "./Utils.js"
|
|
7
|
+
import { PCGRandom, structuralRegionState } from "./Utils.js"
|
|
8
8
|
|
|
9
9
|
/** @internal */
|
|
10
10
|
const randomHashCache = globalValue(
|
|
@@ -72,6 +72,9 @@ export const hash: <A>(self: A) => number = <A>(self: A) => {
|
|
|
72
72
|
* @category hashing
|
|
73
73
|
*/
|
|
74
74
|
export const random: <A extends object>(self: A) => number = (self) => {
|
|
75
|
+
if (structuralRegionState.enabled === true) {
|
|
76
|
+
return 0
|
|
77
|
+
}
|
|
75
78
|
if (!randomHashCache.has(self)) {
|
|
76
79
|
randomHashCache.set(self, number(pcgr.integer(Number.MAX_SAFE_INTEGER)))
|
|
77
80
|
}
|
|
@@ -168,22 +171,36 @@ export const cached: {
|
|
|
168
171
|
if (arguments.length === 1) {
|
|
169
172
|
const self = arguments[0] as object
|
|
170
173
|
return function(hash: number) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
// @ts-expect-error
|
|
175
|
+
const original = self[symbol].bind(self)
|
|
176
|
+
if (structuralRegionState.enabled === false) {
|
|
177
|
+
Object.defineProperty(self, symbol, {
|
|
178
|
+
value() {
|
|
179
|
+
if (structuralRegionState.enabled === true) {
|
|
180
|
+
return original()
|
|
181
|
+
}
|
|
182
|
+
return hash
|
|
183
|
+
},
|
|
184
|
+
enumerable: false
|
|
185
|
+
})
|
|
186
|
+
}
|
|
177
187
|
return hash
|
|
178
188
|
} as any
|
|
179
189
|
}
|
|
180
190
|
const self = arguments[0] as object
|
|
181
191
|
const hash = arguments[1] as number
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
192
|
+
// @ts-expect-error
|
|
193
|
+
const original = self[symbol].bind(self)
|
|
194
|
+
if (structuralRegionState.enabled === false) {
|
|
195
|
+
Object.defineProperty(self, symbol, {
|
|
196
|
+
value() {
|
|
197
|
+
if (structuralRegionState.enabled === true) {
|
|
198
|
+
return original()
|
|
199
|
+
}
|
|
200
|
+
return hash
|
|
201
|
+
},
|
|
202
|
+
enumerable: false
|
|
203
|
+
})
|
|
204
|
+
}
|
|
188
205
|
return hash
|
|
189
206
|
}
|
package/src/HashMap.ts
CHANGED
|
@@ -40,7 +40,7 @@ export declare namespace HashMap {
|
|
|
40
40
|
* This type-level utility extracts the key type `K` from a `HashMap<K, V>` type.
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
43
|
-
* import
|
|
43
|
+
* import { HashMap } from "effect"
|
|
44
44
|
*
|
|
45
45
|
* declare const hm: HashMap.HashMap<string, number>
|
|
46
46
|
*
|
|
@@ -55,7 +55,7 @@ export declare namespace HashMap {
|
|
|
55
55
|
* This type-level utility extracts the value type `V` from a `HashMap<K, V>` type.
|
|
56
56
|
*
|
|
57
57
|
* @example
|
|
58
|
-
* import
|
|
58
|
+
* import { HashMap } from "effect"
|
|
59
59
|
*
|
|
60
60
|
* declare const hm: HashMap.HashMap<string, number>
|
|
61
61
|
*
|