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/dist/esm/Option.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as Equal from "./Equal.js";
|
|
2
2
|
import * as Equivalence from "./Equivalence.js";
|
|
3
3
|
import { constNull, constUndefined, dual, identity, isFunction } from "./Function.js";
|
|
4
|
+
import * as doNotation from "./internal/doNotation.js";
|
|
4
5
|
import * as either from "./internal/either.js";
|
|
5
6
|
import * as option from "./internal/option.js";
|
|
6
7
|
import * as order from "./Order.js";
|
|
@@ -32,11 +33,11 @@ export const some = option.some;
|
|
|
32
33
|
* @param input - The value to check.
|
|
33
34
|
*
|
|
34
35
|
* @example
|
|
35
|
-
* import {
|
|
36
|
+
* import { Option } from "effect"
|
|
36
37
|
*
|
|
37
|
-
* assert.deepStrictEqual(isOption(some(1)), true)
|
|
38
|
-
* assert.deepStrictEqual(isOption(none()), true)
|
|
39
|
-
* assert.deepStrictEqual(isOption({}), false)
|
|
38
|
+
* assert.deepStrictEqual(Option.isOption(Option.some(1)), true)
|
|
39
|
+
* assert.deepStrictEqual(Option.isOption(Option.none()), true)
|
|
40
|
+
* assert.deepStrictEqual(Option.isOption({}), false)
|
|
40
41
|
*
|
|
41
42
|
* @category guards
|
|
42
43
|
* @since 2.0.0
|
|
@@ -48,10 +49,10 @@ export const isOption = option.isOption;
|
|
|
48
49
|
* @param self - The `Option` to check.
|
|
49
50
|
*
|
|
50
51
|
* @example
|
|
51
|
-
* import {
|
|
52
|
+
* import { Option } from "effect"
|
|
52
53
|
*
|
|
53
|
-
* assert.deepStrictEqual(isNone(some(1)), false)
|
|
54
|
-
* assert.deepStrictEqual(isNone(none()), true)
|
|
54
|
+
* assert.deepStrictEqual(Option.isNone(Option.some(1)), false)
|
|
55
|
+
* assert.deepStrictEqual(Option.isNone(Option.none()), true)
|
|
55
56
|
*
|
|
56
57
|
* @category guards
|
|
57
58
|
* @since 2.0.0
|
|
@@ -63,10 +64,10 @@ export const isNone = option.isNone;
|
|
|
63
64
|
* @param self - The `Option` to check.
|
|
64
65
|
*
|
|
65
66
|
* @example
|
|
66
|
-
* import {
|
|
67
|
+
* import { Option } from "effect"
|
|
67
68
|
*
|
|
68
|
-
* assert.deepStrictEqual(isSome(some(1)), true)
|
|
69
|
-
* assert.deepStrictEqual(isSome(none()), false)
|
|
69
|
+
* assert.deepStrictEqual(Option.isSome(Option.some(1)), true)
|
|
70
|
+
* assert.deepStrictEqual(Option.isSome(Option.none()), false)
|
|
70
71
|
*
|
|
71
72
|
* @category guards
|
|
72
73
|
* @since 2.0.0
|
|
@@ -81,16 +82,15 @@ export const isSome = option.isSome;
|
|
|
81
82
|
* @param onSome - The function to be called if the `Option` is `Some`, it will be passed the `Option`'s value and its result will be returned
|
|
82
83
|
*
|
|
83
84
|
* @example
|
|
84
|
-
* import {
|
|
85
|
-
* import { pipe } from "effect/Function"
|
|
85
|
+
* import { pipe, Option } from "effect"
|
|
86
86
|
*
|
|
87
87
|
* assert.deepStrictEqual(
|
|
88
|
-
* pipe(some(1), match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),
|
|
88
|
+
* pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),
|
|
89
89
|
* 'a some containing 1'
|
|
90
90
|
* )
|
|
91
91
|
*
|
|
92
92
|
* assert.deepStrictEqual(
|
|
93
|
-
* pipe(none(), match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),
|
|
93
|
+
* pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),
|
|
94
94
|
* 'a none'
|
|
95
95
|
* )
|
|
96
96
|
*
|
|
@@ -106,12 +106,12 @@ export const match = /*#__PURE__*/dual(2, (self, {
|
|
|
106
106
|
* This function ensures that a type guard definition is type-safe.
|
|
107
107
|
*
|
|
108
108
|
* @example
|
|
109
|
-
* import
|
|
109
|
+
* import { Option } from "effect"
|
|
110
110
|
*
|
|
111
|
-
* const parsePositive = (n: number):
|
|
112
|
-
* n > 0 ?
|
|
111
|
+
* const parsePositive = (n: number): Option.Option<number> =>
|
|
112
|
+
* n > 0 ? Option.some(n) : Option.none()
|
|
113
113
|
*
|
|
114
|
-
* const isPositive =
|
|
114
|
+
* const isPositive = Option.toRefinement(parsePositive)
|
|
115
115
|
*
|
|
116
116
|
* assert.deepStrictEqual(isPositive(1), true)
|
|
117
117
|
* assert.deepStrictEqual(isPositive(-1), false)
|
|
@@ -127,10 +127,10 @@ export const toRefinement = f => a => isSome(f(a));
|
|
|
127
127
|
* @param collection - The `Iterable` to be converted to an `Option`.
|
|
128
128
|
*
|
|
129
129
|
* @example
|
|
130
|
-
* import {
|
|
130
|
+
* import { Option } from "effect"
|
|
131
131
|
*
|
|
132
|
-
* assert.deepStrictEqual(fromIterable([1, 2, 3]), some(1))
|
|
133
|
-
* assert.deepStrictEqual(fromIterable([]), none())
|
|
132
|
+
* assert.deepStrictEqual(Option.fromIterable([1, 2, 3]), Option.some(1))
|
|
133
|
+
* assert.deepStrictEqual(Option.fromIterable([]), Option.none())
|
|
134
134
|
*
|
|
135
135
|
* @category constructors
|
|
136
136
|
* @since 2.0.0
|
|
@@ -147,11 +147,10 @@ export const fromIterable = collection => {
|
|
|
147
147
|
* Alias of {@link fromEither}.
|
|
148
148
|
*
|
|
149
149
|
* @example
|
|
150
|
-
* import
|
|
151
|
-
* import * as E from "effect/Either"
|
|
150
|
+
* import { Option, Either } from "effect"
|
|
152
151
|
*
|
|
153
|
-
* assert.deepStrictEqual(
|
|
154
|
-
* assert.deepStrictEqual(
|
|
152
|
+
* assert.deepStrictEqual(Option.getRight(Either.right('ok')), Option.some('ok'))
|
|
153
|
+
* assert.deepStrictEqual(Option.getRight(Either.left('err')), Option.none())
|
|
155
154
|
*
|
|
156
155
|
* @category conversions
|
|
157
156
|
* @since 2.0.0
|
|
@@ -161,11 +160,10 @@ export const getRight = either.getRight;
|
|
|
161
160
|
* Converts a `Either` to an `Option` discarding the value.
|
|
162
161
|
*
|
|
163
162
|
* @example
|
|
164
|
-
* import
|
|
165
|
-
* import * as E from "effect/Either"
|
|
163
|
+
* import { Option, Either } from "effect"
|
|
166
164
|
*
|
|
167
|
-
* assert.deepStrictEqual(
|
|
168
|
-
* assert.deepStrictEqual(
|
|
165
|
+
* assert.deepStrictEqual(Option.getLeft(Either.right("ok")), Option.none())
|
|
166
|
+
* assert.deepStrictEqual(Option.getLeft(Either.left("a")), Option.some("a"))
|
|
169
167
|
*
|
|
170
168
|
* @category conversions
|
|
171
169
|
* @since 2.0.0
|
|
@@ -178,11 +176,10 @@ export const getLeft = either.getLeft;
|
|
|
178
176
|
* @param onNone - Function that returns the default value to return if the `Option` is `None`.
|
|
179
177
|
*
|
|
180
178
|
* @example
|
|
181
|
-
* import {
|
|
182
|
-
* import { pipe } from "effect/Function"
|
|
179
|
+
* import { pipe, Option } from "effect"
|
|
183
180
|
*
|
|
184
|
-
* assert.deepStrictEqual(pipe(some(1), getOrElse(() => 0)), 1)
|
|
185
|
-
* assert.deepStrictEqual(pipe(none(), getOrElse(() => 0)), 0)
|
|
181
|
+
* assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1)
|
|
182
|
+
* assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0)
|
|
186
183
|
*
|
|
187
184
|
* @category getters
|
|
188
185
|
* @since 2.0.0
|
|
@@ -195,36 +192,35 @@ export const getOrElse = /*#__PURE__*/dual(2, (self, onNone) => isNone(self) ? o
|
|
|
195
192
|
* @param that - The `Option` to return if `self` is `None`.
|
|
196
193
|
*
|
|
197
194
|
* @example
|
|
198
|
-
* import
|
|
199
|
-
* import { pipe } from "effect/Function"
|
|
195
|
+
* import { pipe, Option } from "effect"
|
|
200
196
|
*
|
|
201
197
|
* assert.deepStrictEqual(
|
|
202
198
|
* pipe(
|
|
203
|
-
*
|
|
204
|
-
*
|
|
199
|
+
* Option.none(),
|
|
200
|
+
* Option.orElse(() => Option.none())
|
|
205
201
|
* ),
|
|
206
|
-
*
|
|
202
|
+
* Option.none()
|
|
207
203
|
* )
|
|
208
204
|
* assert.deepStrictEqual(
|
|
209
205
|
* pipe(
|
|
210
|
-
*
|
|
211
|
-
*
|
|
206
|
+
* Option.some('a'),
|
|
207
|
+
* Option.orElse(() => Option.none())
|
|
212
208
|
* ),
|
|
213
|
-
*
|
|
209
|
+
* Option.some('a')
|
|
214
210
|
* )
|
|
215
211
|
* assert.deepStrictEqual(
|
|
216
212
|
* pipe(
|
|
217
|
-
*
|
|
218
|
-
*
|
|
213
|
+
* Option.none(),
|
|
214
|
+
* Option.orElse(() => Option.some('b'))
|
|
219
215
|
* ),
|
|
220
|
-
*
|
|
216
|
+
* Option.some('b')
|
|
221
217
|
* )
|
|
222
218
|
* assert.deepStrictEqual(
|
|
223
219
|
* pipe(
|
|
224
|
-
*
|
|
225
|
-
*
|
|
220
|
+
* Option.some('a'),
|
|
221
|
+
* Option.orElse(() => Option.some('b'))
|
|
226
222
|
* ),
|
|
227
|
-
*
|
|
223
|
+
* Option.some('a')
|
|
228
224
|
* )
|
|
229
225
|
*
|
|
230
226
|
* @category error handling
|
|
@@ -238,22 +234,21 @@ export const orElse = /*#__PURE__*/dual(2, (self, that) => isNone(self) ? that()
|
|
|
238
234
|
* @param onNone - Function that returns the default value to return if the `Option` is `None`.
|
|
239
235
|
*
|
|
240
236
|
* @example
|
|
241
|
-
* import
|
|
242
|
-
* import { pipe } from "effect/Function"
|
|
237
|
+
* import { pipe, Option } from "effect"
|
|
243
238
|
*
|
|
244
239
|
* assert.deepStrictEqual(
|
|
245
240
|
* pipe(
|
|
246
|
-
*
|
|
247
|
-
*
|
|
241
|
+
* Option.none(),
|
|
242
|
+
* Option.orElseSome(() => 'b')
|
|
248
243
|
* ),
|
|
249
|
-
*
|
|
244
|
+
* Option.some('b')
|
|
250
245
|
* )
|
|
251
246
|
* assert.deepStrictEqual(
|
|
252
247
|
* pipe(
|
|
253
|
-
*
|
|
254
|
-
*
|
|
248
|
+
* Option.some('a'),
|
|
249
|
+
* Option.orElseSome(() => 'b')
|
|
255
250
|
* ),
|
|
256
|
-
*
|
|
251
|
+
* Option.some('a')
|
|
257
252
|
* )
|
|
258
253
|
*
|
|
259
254
|
* @category error handling
|
|
@@ -279,9 +274,9 @@ export const orElseEither = /*#__PURE__*/dual(2, (self, that) => isNone(self) ?
|
|
|
279
274
|
* @param collection - An iterable collection of `Option` to be searched.
|
|
280
275
|
*
|
|
281
276
|
* @example
|
|
282
|
-
* import
|
|
277
|
+
* import { Option } from "effect"
|
|
283
278
|
*
|
|
284
|
-
* assert.deepStrictEqual(
|
|
279
|
+
* assert.deepStrictEqual(Option.firstSomeOf([Option.none(), Option.some(1), Option.some(2)]), Option.some(1))
|
|
285
280
|
*
|
|
286
281
|
* @category error handling
|
|
287
282
|
* @since 2.0.0
|
|
@@ -302,11 +297,11 @@ export const firstSomeOf = collection => {
|
|
|
302
297
|
* @param nullableValue - The nullable value to be converted to an `Option`.
|
|
303
298
|
*
|
|
304
299
|
* @example
|
|
305
|
-
* import
|
|
300
|
+
* import { Option } from "effect"
|
|
306
301
|
*
|
|
307
|
-
* assert.deepStrictEqual(
|
|
308
|
-
* assert.deepStrictEqual(
|
|
309
|
-
* assert.deepStrictEqual(
|
|
302
|
+
* assert.deepStrictEqual(Option.fromNullable(undefined), Option.none())
|
|
303
|
+
* assert.deepStrictEqual(Option.fromNullable(null), Option.none())
|
|
304
|
+
* assert.deepStrictEqual(Option.fromNullable(1), Option.some(1))
|
|
310
305
|
*
|
|
311
306
|
* @category conversions
|
|
312
307
|
* @since 2.0.0
|
|
@@ -316,17 +311,17 @@ export const fromNullable = nullableValue => nullableValue == null ? none() : so
|
|
|
316
311
|
* This API is useful for lifting a function that returns `null` or `undefined` into the `Option` context.
|
|
317
312
|
*
|
|
318
313
|
* @example
|
|
319
|
-
* import
|
|
314
|
+
* import { Option } from "effect"
|
|
320
315
|
*
|
|
321
316
|
* const parse = (s: string): number | undefined => {
|
|
322
317
|
* const n = parseFloat(s)
|
|
323
318
|
* return isNaN(n) ? undefined : n
|
|
324
319
|
* }
|
|
325
320
|
*
|
|
326
|
-
* const parseOption =
|
|
321
|
+
* const parseOption = Option.liftNullable(parse)
|
|
327
322
|
*
|
|
328
|
-
* assert.deepStrictEqual(parseOption('1'),
|
|
329
|
-
* assert.deepStrictEqual(parseOption('not a number'),
|
|
323
|
+
* assert.deepStrictEqual(parseOption('1'), Option.some(1))
|
|
324
|
+
* assert.deepStrictEqual(parseOption('not a number'), Option.none())
|
|
330
325
|
*
|
|
331
326
|
* @category conversions
|
|
332
327
|
* @since 2.0.0
|
|
@@ -338,10 +333,10 @@ export const liftNullable = f => (...a) => fromNullable(f(...a));
|
|
|
338
333
|
* @param self - The `Option` to extract the value from.
|
|
339
334
|
*
|
|
340
335
|
* @example
|
|
341
|
-
* import
|
|
336
|
+
* import { Option } from "effect"
|
|
342
337
|
*
|
|
343
|
-
* assert.deepStrictEqual(
|
|
344
|
-
* assert.deepStrictEqual(
|
|
338
|
+
* assert.deepStrictEqual(Option.getOrNull(Option.some(1)), 1)
|
|
339
|
+
* assert.deepStrictEqual(Option.getOrNull(Option.none()), null)
|
|
345
340
|
*
|
|
346
341
|
* @category getters
|
|
347
342
|
* @since 2.0.0
|
|
@@ -353,10 +348,10 @@ export const getOrNull = /*#__PURE__*/getOrElse(constNull);
|
|
|
353
348
|
* @param self - The `Option` to extract the value from.
|
|
354
349
|
*
|
|
355
350
|
* @example
|
|
356
|
-
* import
|
|
351
|
+
* import { Option } from "effect"
|
|
357
352
|
*
|
|
358
|
-
* assert.deepStrictEqual(
|
|
359
|
-
* assert.deepStrictEqual(
|
|
353
|
+
* assert.deepStrictEqual(Option.getOrUndefined(Option.some(1)), 1)
|
|
354
|
+
* assert.deepStrictEqual(Option.getOrUndefined(Option.none()), undefined)
|
|
360
355
|
*
|
|
361
356
|
* @category getters
|
|
362
357
|
* @since 2.0.0
|
|
@@ -371,12 +366,12 @@ export const getOrUndefined = /*#__PURE__*/getOrElse(constUndefined);
|
|
|
371
366
|
* @param f - the function that can throw exceptions.
|
|
372
367
|
*
|
|
373
368
|
* @example
|
|
374
|
-
* import
|
|
369
|
+
* import { Option } from "effect"
|
|
375
370
|
*
|
|
376
|
-
* const parse =
|
|
371
|
+
* const parse = Option.liftThrowable(JSON.parse)
|
|
377
372
|
*
|
|
378
|
-
* assert.deepStrictEqual(parse("1"),
|
|
379
|
-
* assert.deepStrictEqual(parse(""),
|
|
373
|
+
* assert.deepStrictEqual(parse("1"), Option.some(1))
|
|
374
|
+
* assert.deepStrictEqual(parse(""), Option.none())
|
|
380
375
|
*
|
|
381
376
|
* @category conversions
|
|
382
377
|
* @since 2.0.0
|
|
@@ -397,13 +392,13 @@ export const liftThrowable = f => (...a) => {
|
|
|
397
392
|
* @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.
|
|
398
393
|
*
|
|
399
394
|
* @example
|
|
400
|
-
* import
|
|
395
|
+
* import { Option } from "effect"
|
|
401
396
|
*
|
|
402
397
|
* assert.deepStrictEqual(
|
|
403
|
-
*
|
|
398
|
+
* Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),
|
|
404
399
|
* 1
|
|
405
400
|
* )
|
|
406
|
-
* assert.throws(() =>
|
|
401
|
+
* assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))
|
|
407
402
|
*
|
|
408
403
|
* @category conversions
|
|
409
404
|
* @since 2.0.0
|
|
@@ -423,10 +418,10 @@ export const getOrThrowWith = /*#__PURE__*/dual(2, (self, onNone) => {
|
|
|
423
418
|
* @throws `Error("getOrThrow called on a None")`
|
|
424
419
|
*
|
|
425
420
|
* @example
|
|
426
|
-
* import
|
|
421
|
+
* import { Option } from "effect"
|
|
427
422
|
*
|
|
428
|
-
* assert.deepStrictEqual(
|
|
429
|
-
* assert.throws(() =>
|
|
423
|
+
* assert.deepStrictEqual(Option.getOrThrow(Option.some(1)), 1)
|
|
424
|
+
* assert.throws(() => Option.getOrThrow(Option.none()))
|
|
430
425
|
*
|
|
431
426
|
* @category conversions
|
|
432
427
|
* @since 2.0.0
|
|
@@ -485,8 +480,7 @@ export const andThen = /*#__PURE__*/dual(2, (self, f) => flatMap(self, a => {
|
|
|
485
480
|
* This is `flatMap` + `fromNullable`, useful when working with optional values.
|
|
486
481
|
*
|
|
487
482
|
* @example
|
|
488
|
-
* import {
|
|
489
|
-
* import { pipe } from "effect/Function"
|
|
483
|
+
* import { pipe, Option } from "effect"
|
|
490
484
|
*
|
|
491
485
|
* interface Employee {
|
|
492
486
|
* company?: {
|
|
@@ -502,20 +496,20 @@ export const andThen = /*#__PURE__*/dual(2, (self, f) => flatMap(self, a => {
|
|
|
502
496
|
*
|
|
503
497
|
* assert.deepStrictEqual(
|
|
504
498
|
* pipe(
|
|
505
|
-
* some(employee1),
|
|
506
|
-
* flatMapNullable(employee => employee.company?.address?.street?.name),
|
|
499
|
+
* Option.some(employee1),
|
|
500
|
+
* Option.flatMapNullable(employee => employee.company?.address?.street?.name),
|
|
507
501
|
* ),
|
|
508
|
-
* some('high street')
|
|
502
|
+
* Option.some('high street')
|
|
509
503
|
* )
|
|
510
504
|
*
|
|
511
505
|
* const employee2: Employee = { company: { address: { street: {} } } }
|
|
512
506
|
*
|
|
513
507
|
* assert.deepStrictEqual(
|
|
514
508
|
* pipe(
|
|
515
|
-
* some(employee2),
|
|
516
|
-
* flatMapNullable(employee => employee.company?.address?.street?.name),
|
|
509
|
+
* Option.some(employee2),
|
|
510
|
+
* Option.flatMapNullable(employee => employee.company?.address?.street?.name),
|
|
517
511
|
* ),
|
|
518
|
-
* none()
|
|
512
|
+
* Option.none()
|
|
519
513
|
* )
|
|
520
514
|
*
|
|
521
515
|
* @category sequencing
|
|
@@ -559,13 +553,13 @@ export const zipLeft = /*#__PURE__*/dual(2, (self, that) => tap(self, () => that
|
|
|
559
553
|
* @param self - The `Option` to apply the function to
|
|
560
554
|
*
|
|
561
555
|
* @example
|
|
562
|
-
* import
|
|
556
|
+
* import { Option } from "effect"
|
|
563
557
|
*
|
|
564
|
-
* const getInteger = (n: number) => Number.isInteger(n) ?
|
|
558
|
+
* const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()
|
|
565
559
|
*
|
|
566
|
-
* assert.deepStrictEqual(
|
|
567
|
-
* assert.deepStrictEqual(
|
|
568
|
-
* assert.deepStrictEqual(
|
|
560
|
+
* assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none())
|
|
561
|
+
* assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1))
|
|
562
|
+
* assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none())
|
|
569
563
|
*
|
|
570
564
|
* @category sequencing
|
|
571
565
|
* @since 2.0.0
|
|
@@ -603,11 +597,11 @@ export const productMany = (self, collection) => {
|
|
|
603
597
|
* @param fields - the struct of `Option`s to be sequenced.
|
|
604
598
|
*
|
|
605
599
|
* @example
|
|
606
|
-
* import
|
|
600
|
+
* import { Option } from "effect"
|
|
607
601
|
*
|
|
608
|
-
* assert.deepStrictEqual(
|
|
609
|
-
* assert.deepStrictEqual(
|
|
610
|
-
* assert.deepStrictEqual(
|
|
602
|
+
* assert.deepStrictEqual(Option.all([Option.some(1), Option.some(2)]), Option.some([1, 2]))
|
|
603
|
+
* assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.some("hello") }), Option.some({ a: 1, b: "hello" }))
|
|
604
|
+
* assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.none() }), Option.none())
|
|
611
605
|
*
|
|
612
606
|
* @category combining
|
|
613
607
|
* @since 2.0.0
|
|
@@ -642,18 +636,18 @@ export const all = input => {
|
|
|
642
636
|
* @param f - The function used to combine the values of the two `Option`s
|
|
643
637
|
*
|
|
644
638
|
* @example
|
|
645
|
-
* import
|
|
639
|
+
* import { Option } from "effect"
|
|
646
640
|
*
|
|
647
641
|
* type Complex = [real: number, imaginary: number]
|
|
648
642
|
*
|
|
649
643
|
* const complex = (real: number, imaginary: number): Complex => [real, imaginary]
|
|
650
644
|
*
|
|
651
|
-
* assert.deepStrictEqual(
|
|
652
|
-
* assert.deepStrictEqual(
|
|
653
|
-
* assert.deepStrictEqual(
|
|
654
|
-
* assert.deepStrictEqual(
|
|
645
|
+
* assert.deepStrictEqual(Option.zipWith(Option.none(), Option.none(), complex), Option.none())
|
|
646
|
+
* assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.none(), complex), Option.none())
|
|
647
|
+
* assert.deepStrictEqual(Option.zipWith(Option.none(), Option.some(1), complex), Option.none())
|
|
648
|
+
* assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.some(2), complex), Option.some([1, 2]))
|
|
655
649
|
*
|
|
656
|
-
* assert.deepStrictEqual(
|
|
650
|
+
* assert.deepStrictEqual(Option.zipWith(Option.some(1), complex)(Option.some(2)), Option.some([2, 1]))
|
|
657
651
|
*
|
|
658
652
|
* @category zipping
|
|
659
653
|
* @since 2.0.0
|
|
@@ -672,11 +666,10 @@ export const ap = /*#__PURE__*/dual(2, (self, that) => zipWith(self, that, (f, a
|
|
|
672
666
|
* @param f - The reducing function that takes the current accumulator value and the unwrapped value of an `Option<A>`.
|
|
673
667
|
*
|
|
674
668
|
* @example
|
|
675
|
-
* import {
|
|
676
|
-
* import { pipe } from "effect/Function"
|
|
669
|
+
* import { pipe, Option } from "effect"
|
|
677
670
|
*
|
|
678
|
-
* const iterable = [some(1), none(), some(2), none()]
|
|
679
|
-
* assert.deepStrictEqual(pipe(iterable, reduceCompact(0, (b, a) => b + a)), 3)
|
|
671
|
+
* const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]
|
|
672
|
+
* assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3)
|
|
680
673
|
*
|
|
681
674
|
* @category folding
|
|
682
675
|
* @since 2.0.0
|
|
@@ -698,10 +691,10 @@ export const reduceCompact = /*#__PURE__*/dual(3, (self, b, f) => {
|
|
|
698
691
|
* @param self - The `Option` to convert to an array.
|
|
699
692
|
*
|
|
700
693
|
* @example
|
|
701
|
-
* import
|
|
694
|
+
* import { Option } from "effect"
|
|
702
695
|
*
|
|
703
|
-
* assert.deepStrictEqual(
|
|
704
|
-
* assert.deepStrictEqual(
|
|
696
|
+
* assert.deepStrictEqual(Option.toArray(Option.some(1)), [1])
|
|
697
|
+
* assert.deepStrictEqual(Option.toArray(Option.none()), [])
|
|
705
698
|
*
|
|
706
699
|
* @category conversions
|
|
707
700
|
* @since 2.0.0
|
|
@@ -727,13 +720,13 @@ export const partitionMap = /*#__PURE__*/dual(2, (self, f) => {
|
|
|
727
720
|
* @param f - A function to apply to the value of the `Option`.
|
|
728
721
|
*
|
|
729
722
|
* @example
|
|
730
|
-
* import
|
|
723
|
+
* import { Option } from "effect"
|
|
731
724
|
*
|
|
732
|
-
* const evenNumber = (n: number) => n % 2 === 0 ?
|
|
725
|
+
* const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none()
|
|
733
726
|
*
|
|
734
|
-
* assert.deepStrictEqual(
|
|
735
|
-
* assert.deepStrictEqual(
|
|
736
|
-
* assert.deepStrictEqual(
|
|
727
|
+
* assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none())
|
|
728
|
+
* assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none())
|
|
729
|
+
* assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2))
|
|
737
730
|
*
|
|
738
731
|
* @category filtering
|
|
739
732
|
* @since 2.0.0
|
|
@@ -748,21 +741,21 @@ export const filterMap = /*#__PURE__*/dual(2, (self, f) => isNone(self) ? none()
|
|
|
748
741
|
* @param fb - The `Option` to filter.
|
|
749
742
|
*
|
|
750
743
|
* @example
|
|
751
|
-
* import
|
|
744
|
+
* import { Option } from "effect"
|
|
752
745
|
*
|
|
753
746
|
* // predicate
|
|
754
747
|
* const isEven = (n: number) => n % 2 === 0
|
|
755
748
|
*
|
|
756
|
-
* assert.deepStrictEqual(
|
|
757
|
-
* assert.deepStrictEqual(
|
|
758
|
-
* assert.deepStrictEqual(
|
|
749
|
+
* assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())
|
|
750
|
+
* assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())
|
|
751
|
+
* assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))
|
|
759
752
|
*
|
|
760
753
|
* // refinement
|
|
761
754
|
* const isNumber = (v: unknown): v is number => typeof v === "number"
|
|
762
755
|
*
|
|
763
|
-
* assert.deepStrictEqual(
|
|
764
|
-
* assert.deepStrictEqual(
|
|
765
|
-
* assert.deepStrictEqual(
|
|
756
|
+
* assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())
|
|
757
|
+
* assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())
|
|
758
|
+
* assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))
|
|
766
759
|
*
|
|
767
760
|
* @category filtering
|
|
768
761
|
* @since 2.0.0
|
|
@@ -770,15 +763,14 @@ export const filterMap = /*#__PURE__*/dual(2, (self, f) => isNone(self) ? none()
|
|
|
770
763
|
export const filter = /*#__PURE__*/dual(2, (self, predicate) => filterMap(self, b => predicate(b) ? option.some(b) : option.none));
|
|
771
764
|
/**
|
|
772
765
|
* @example
|
|
773
|
-
* import {
|
|
774
|
-
* import * as N from 'effect/Number'
|
|
766
|
+
* import { Option, Number } from "effect"
|
|
775
767
|
*
|
|
776
|
-
* const isEquivalent = getEquivalence(
|
|
777
|
-
* assert.deepStrictEqual(isEquivalent(none(), none()), true)
|
|
778
|
-
* assert.deepStrictEqual(isEquivalent(none(), some(1)), false)
|
|
779
|
-
* assert.deepStrictEqual(isEquivalent(some(1), none()), false)
|
|
780
|
-
* assert.deepStrictEqual(isEquivalent(some(1), some(2)), false)
|
|
781
|
-
* assert.deepStrictEqual(isEquivalent(some(1), some(1)), true)
|
|
768
|
+
* const isEquivalent = Option.getEquivalence(Number.Equivalence)
|
|
769
|
+
* assert.deepStrictEqual(isEquivalent(Option.none(), Option.none()), true)
|
|
770
|
+
* assert.deepStrictEqual(isEquivalent(Option.none(), Option.some(1)), false)
|
|
771
|
+
* assert.deepStrictEqual(isEquivalent(Option.some(1), Option.none()), false)
|
|
772
|
+
* assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(2)), false)
|
|
773
|
+
* assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(1)), true)
|
|
782
774
|
*
|
|
783
775
|
* @category equivalence
|
|
784
776
|
* @since 2.0.0
|
|
@@ -792,16 +784,14 @@ export const getEquivalence = isEquivalent => Equivalence.make((x, y) => x === y
|
|
|
792
784
|
* `None` is considered to be less than any `Some` value.
|
|
793
785
|
*
|
|
794
786
|
* @example
|
|
795
|
-
* import {
|
|
796
|
-
* import * as N from 'effect/Number'
|
|
797
|
-
* import { pipe } from "effect/Function"
|
|
787
|
+
* import { pipe, Option, Number } from "effect"
|
|
798
788
|
*
|
|
799
|
-
* const O = getOrder(
|
|
800
|
-
* assert.deepStrictEqual(O(none(), none()), 0)
|
|
801
|
-
* assert.deepStrictEqual(O(none(), some(1)), -1)
|
|
802
|
-
* assert.deepStrictEqual(O(some(1), none()), 1)
|
|
803
|
-
* assert.deepStrictEqual(O(some(1), some(2)), -1)
|
|
804
|
-
* assert.deepStrictEqual(O(some(1), some(1)), 0)
|
|
789
|
+
* const O = Option.getOrder(Number.Order)
|
|
790
|
+
* assert.deepStrictEqual(O(Option.none(), Option.none()), 0)
|
|
791
|
+
* assert.deepStrictEqual(O(Option.none(), Option.some(1)), -1)
|
|
792
|
+
* assert.deepStrictEqual(O(Option.some(1), Option.none()), 1)
|
|
793
|
+
* assert.deepStrictEqual(O(Option.some(1), Option.some(2)), -1)
|
|
794
|
+
* assert.deepStrictEqual(O(Option.some(1), Option.some(1)), 0)
|
|
805
795
|
*
|
|
806
796
|
* @category sorting
|
|
807
797
|
* @since 2.0.0
|
|
@@ -823,12 +813,12 @@ export const lift2 = f => dual(2, (self, that) => zipWith(self, that, f));
|
|
|
823
813
|
* @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.
|
|
824
814
|
*
|
|
825
815
|
* @example
|
|
826
|
-
* import
|
|
816
|
+
* import { Option } from "effect"
|
|
827
817
|
*
|
|
828
|
-
* const getOption =
|
|
818
|
+
* const getOption = Option.liftPredicate((n: number) => n >= 0)
|
|
829
819
|
*
|
|
830
|
-
* assert.deepStrictEqual(getOption(-1),
|
|
831
|
-
* assert.deepStrictEqual(getOption(1),
|
|
820
|
+
* assert.deepStrictEqual(getOption(-1), Option.none())
|
|
821
|
+
* assert.deepStrictEqual(getOption(1), Option.some(1))
|
|
832
822
|
*
|
|
833
823
|
* @category lifting
|
|
834
824
|
* @since 2.0.0
|
|
@@ -842,13 +832,11 @@ export const liftPredicate = predicate => b => predicate(b) ? some(b) : none();
|
|
|
842
832
|
* @param a - The value to compare against the `Option`.
|
|
843
833
|
*
|
|
844
834
|
* @example
|
|
845
|
-
* import {
|
|
846
|
-
* import { Equivalence } from 'effect/Number'
|
|
847
|
-
* import { pipe } from "effect/Function"
|
|
835
|
+
* import { pipe, Option, Number } from "effect"
|
|
848
836
|
*
|
|
849
|
-
* assert.deepStrictEqual(pipe(some(2), containsWith(Equivalence)(2)), true)
|
|
850
|
-
* assert.deepStrictEqual(pipe(some(1), containsWith(Equivalence)(2)), false)
|
|
851
|
-
* assert.deepStrictEqual(pipe(none(), containsWith(Equivalence)(2)), false)
|
|
837
|
+
* assert.deepStrictEqual(pipe(Option.some(2), Option.containsWith(Number.Equivalence)(2)), true)
|
|
838
|
+
* assert.deepStrictEqual(pipe(Option.some(1), Option.containsWith(Number.Equivalence)(2)), false)
|
|
839
|
+
* assert.deepStrictEqual(pipe(Option.none(), Option.containsWith(Number.Equivalence)(2)), false)
|
|
852
840
|
*
|
|
853
841
|
* @category elements
|
|
854
842
|
* @since 2.0.0
|
|
@@ -869,14 +857,13 @@ export const contains = /*#__PURE__*/containsWith(_equivalence);
|
|
|
869
857
|
* @param predicate - The condition to check.
|
|
870
858
|
*
|
|
871
859
|
* @example
|
|
872
|
-
* import {
|
|
873
|
-
* import { pipe } from "effect/Function"
|
|
860
|
+
* import { pipe, Option } from "effect"
|
|
874
861
|
*
|
|
875
862
|
* const isEven = (n: number) => n % 2 === 0
|
|
876
863
|
*
|
|
877
|
-
* assert.deepStrictEqual(pipe(some(2), exists(isEven)), true)
|
|
878
|
-
* assert.deepStrictEqual(pipe(some(1), exists(isEven)), false)
|
|
879
|
-
* assert.deepStrictEqual(pipe(none(), exists(isEven)), false)
|
|
864
|
+
* assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)
|
|
865
|
+
* assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)
|
|
866
|
+
* assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)
|
|
880
867
|
*
|
|
881
868
|
* @since 2.0.0
|
|
882
869
|
*/
|
|
@@ -885,29 +872,127 @@ export const exists = /*#__PURE__*/dual(2, (self, refinement) => isNone(self) ?
|
|
|
885
872
|
// do notation
|
|
886
873
|
// -------------------------------------------------------------------------------------
|
|
887
874
|
/**
|
|
875
|
+
* 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`.
|
|
876
|
+
*
|
|
877
|
+
* Here's how the do simulation works:
|
|
878
|
+
*
|
|
879
|
+
* 1. Start the do simulation using the `Do` value
|
|
880
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values
|
|
881
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
882
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
883
|
+
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
884
|
+
*
|
|
885
|
+
* @see {@link Do}
|
|
886
|
+
* @see {@link bind}
|
|
887
|
+
* @see {@link let_ let}
|
|
888
|
+
*
|
|
889
|
+
* @example
|
|
890
|
+
* import { Option, pipe } from "effect"
|
|
891
|
+
*
|
|
892
|
+
* const result = pipe(
|
|
893
|
+
* Option.Do,
|
|
894
|
+
* Option.bind("x", () => Option.some(2)),
|
|
895
|
+
* Option.bind("y", () => Option.some(3)),
|
|
896
|
+
* Option.let("sum", ({ x, y }) => x + y),
|
|
897
|
+
* Option.filter(({ x, y }) => x * y > 5)
|
|
898
|
+
* )
|
|
899
|
+
* assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))
|
|
900
|
+
*
|
|
888
901
|
* @category do notation
|
|
889
902
|
* @since 2.0.0
|
|
890
903
|
*/
|
|
891
|
-
export const bindTo = /*#__PURE__*/
|
|
892
|
-
|
|
893
|
-
})));
|
|
894
|
-
const let_ = /*#__PURE__*/dual(3, (self, name, f) => map(self, a => Object.assign({}, a, {
|
|
895
|
-
[name]: f(a)
|
|
896
|
-
})));
|
|
904
|
+
export const bindTo = /*#__PURE__*/doNotation.bindTo(map);
|
|
905
|
+
const let_ = /*#__PURE__*/doNotation.let_(map);
|
|
897
906
|
export {
|
|
898
907
|
/**
|
|
908
|
+
* 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`.
|
|
909
|
+
*
|
|
910
|
+
* Here's how the do simulation works:
|
|
911
|
+
*
|
|
912
|
+
* 1. Start the do simulation using the `Do` value
|
|
913
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values
|
|
914
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
915
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
916
|
+
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
917
|
+
*
|
|
918
|
+
* @see {@link Do}
|
|
919
|
+
* @see {@link bind}
|
|
920
|
+
* @see {@link bindTo}
|
|
921
|
+
*
|
|
922
|
+
* @example
|
|
923
|
+
* import { Option, pipe } from "effect"
|
|
924
|
+
*
|
|
925
|
+
* const result = pipe(
|
|
926
|
+
* Option.Do,
|
|
927
|
+
* Option.bind("x", () => Option.some(2)),
|
|
928
|
+
* Option.bind("y", () => Option.some(3)),
|
|
929
|
+
* Option.let("sum", ({ x, y }) => x + y),
|
|
930
|
+
* Option.filter(({ x, y }) => x * y > 5)
|
|
931
|
+
* )
|
|
932
|
+
* assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))
|
|
933
|
+
*
|
|
899
934
|
* @category do notation
|
|
900
935
|
* @since 2.0.0
|
|
901
936
|
*/
|
|
902
937
|
let_ as let };
|
|
903
938
|
/**
|
|
939
|
+
* 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`.
|
|
940
|
+
*
|
|
941
|
+
* Here's how the do simulation works:
|
|
942
|
+
*
|
|
943
|
+
* 1. Start the do simulation using the `Do` value
|
|
944
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values
|
|
945
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
946
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
947
|
+
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
948
|
+
*
|
|
949
|
+
* @see {@link Do}
|
|
950
|
+
* @see {@link bindTo}
|
|
951
|
+
* @see {@link let_ let}
|
|
952
|
+
*
|
|
953
|
+
* @example
|
|
954
|
+
* import { Option, pipe } from "effect"
|
|
955
|
+
*
|
|
956
|
+
* const result = pipe(
|
|
957
|
+
* Option.Do,
|
|
958
|
+
* Option.bind("x", () => Option.some(2)),
|
|
959
|
+
* Option.bind("y", () => Option.some(3)),
|
|
960
|
+
* Option.let("sum", ({ x, y }) => x + y),
|
|
961
|
+
* Option.filter(({ x, y }) => x * y > 5)
|
|
962
|
+
* )
|
|
963
|
+
* assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))
|
|
964
|
+
*
|
|
904
965
|
* @category do notation
|
|
905
966
|
* @since 2.0.0
|
|
906
967
|
*/
|
|
907
|
-
export const bind = /*#__PURE__*/
|
|
908
|
-
[name]: b
|
|
909
|
-
}))));
|
|
968
|
+
export const bind = /*#__PURE__*/doNotation.bind(map, flatMap);
|
|
910
969
|
/**
|
|
970
|
+
* 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`.
|
|
971
|
+
*
|
|
972
|
+
* Here's how the do simulation works:
|
|
973
|
+
*
|
|
974
|
+
* 1. Start the do simulation using the `Do` value
|
|
975
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values
|
|
976
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
977
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
978
|
+
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
979
|
+
*
|
|
980
|
+
* @see {@link bindTo}
|
|
981
|
+
* @see {@link bind}
|
|
982
|
+
* @see {@link let_ let}
|
|
983
|
+
*
|
|
984
|
+
* @example
|
|
985
|
+
* import { Option, pipe } from "effect"
|
|
986
|
+
*
|
|
987
|
+
* const result = pipe(
|
|
988
|
+
* Option.Do,
|
|
989
|
+
* Option.bind("x", () => Option.some(2)),
|
|
990
|
+
* Option.bind("y", () => Option.some(3)),
|
|
991
|
+
* Option.let("sum", ({ x, y }) => x + y),
|
|
992
|
+
* Option.filter(({ x, y }) => x * y > 5)
|
|
993
|
+
* )
|
|
994
|
+
* assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))
|
|
995
|
+
*
|
|
911
996
|
* @category do notation
|
|
912
997
|
* @since 2.0.0
|
|
913
998
|
*/
|