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/dts/Option.d.ts
CHANGED
|
@@ -110,11 +110,11 @@ export declare const some: <A>(value: A) => Option<A>;
|
|
|
110
110
|
* @param input - The value to check.
|
|
111
111
|
*
|
|
112
112
|
* @example
|
|
113
|
-
* import {
|
|
113
|
+
* import { Option } from "effect"
|
|
114
114
|
*
|
|
115
|
-
* assert.deepStrictEqual(isOption(some(1)), true)
|
|
116
|
-
* assert.deepStrictEqual(isOption(none()), true)
|
|
117
|
-
* assert.deepStrictEqual(isOption({}), false)
|
|
115
|
+
* assert.deepStrictEqual(Option.isOption(Option.some(1)), true)
|
|
116
|
+
* assert.deepStrictEqual(Option.isOption(Option.none()), true)
|
|
117
|
+
* assert.deepStrictEqual(Option.isOption({}), false)
|
|
118
118
|
*
|
|
119
119
|
* @category guards
|
|
120
120
|
* @since 2.0.0
|
|
@@ -126,10 +126,10 @@ export declare const isOption: (input: unknown) => input is Option<unknown>;
|
|
|
126
126
|
* @param self - The `Option` to check.
|
|
127
127
|
*
|
|
128
128
|
* @example
|
|
129
|
-
* import {
|
|
129
|
+
* import { Option } from "effect"
|
|
130
130
|
*
|
|
131
|
-
* assert.deepStrictEqual(isNone(some(1)), false)
|
|
132
|
-
* assert.deepStrictEqual(isNone(none()), true)
|
|
131
|
+
* assert.deepStrictEqual(Option.isNone(Option.some(1)), false)
|
|
132
|
+
* assert.deepStrictEqual(Option.isNone(Option.none()), true)
|
|
133
133
|
*
|
|
134
134
|
* @category guards
|
|
135
135
|
* @since 2.0.0
|
|
@@ -141,10 +141,10 @@ export declare const isNone: <A>(self: Option<A>) => self is None<A>;
|
|
|
141
141
|
* @param self - The `Option` to check.
|
|
142
142
|
*
|
|
143
143
|
* @example
|
|
144
|
-
* import {
|
|
144
|
+
* import { Option } from "effect"
|
|
145
145
|
*
|
|
146
|
-
* assert.deepStrictEqual(isSome(some(1)), true)
|
|
147
|
-
* assert.deepStrictEqual(isSome(none()), false)
|
|
146
|
+
* assert.deepStrictEqual(Option.isSome(Option.some(1)), true)
|
|
147
|
+
* assert.deepStrictEqual(Option.isSome(Option.none()), false)
|
|
148
148
|
*
|
|
149
149
|
* @category guards
|
|
150
150
|
* @since 2.0.0
|
|
@@ -159,16 +159,15 @@ export declare const isSome: <A>(self: Option<A>) => self is Some<A>;
|
|
|
159
159
|
* @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
|
|
160
160
|
*
|
|
161
161
|
* @example
|
|
162
|
-
* import {
|
|
163
|
-
* import { pipe } from "effect/Function"
|
|
162
|
+
* import { pipe, Option } from "effect"
|
|
164
163
|
*
|
|
165
164
|
* assert.deepStrictEqual(
|
|
166
|
-
* pipe(some(1), match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),
|
|
165
|
+
* pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),
|
|
167
166
|
* 'a some containing 1'
|
|
168
167
|
* )
|
|
169
168
|
*
|
|
170
169
|
* assert.deepStrictEqual(
|
|
171
|
-
* pipe(none(), match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),
|
|
170
|
+
* pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),
|
|
172
171
|
* 'a none'
|
|
173
172
|
* )
|
|
174
173
|
*
|
|
@@ -190,12 +189,12 @@ export declare const match: {
|
|
|
190
189
|
* This function ensures that a type guard definition is type-safe.
|
|
191
190
|
*
|
|
192
191
|
* @example
|
|
193
|
-
* import
|
|
192
|
+
* import { Option } from "effect"
|
|
194
193
|
*
|
|
195
|
-
* const parsePositive = (n: number):
|
|
196
|
-
* n > 0 ?
|
|
194
|
+
* const parsePositive = (n: number): Option.Option<number> =>
|
|
195
|
+
* n > 0 ? Option.some(n) : Option.none()
|
|
197
196
|
*
|
|
198
|
-
* const isPositive =
|
|
197
|
+
* const isPositive = Option.toRefinement(parsePositive)
|
|
199
198
|
*
|
|
200
199
|
* assert.deepStrictEqual(isPositive(1), true)
|
|
201
200
|
* assert.deepStrictEqual(isPositive(-1), false)
|
|
@@ -211,10 +210,10 @@ export declare const toRefinement: <A, B extends A>(f: (a: A) => Option<B>) => (
|
|
|
211
210
|
* @param collection - The `Iterable` to be converted to an `Option`.
|
|
212
211
|
*
|
|
213
212
|
* @example
|
|
214
|
-
* import {
|
|
213
|
+
* import { Option } from "effect"
|
|
215
214
|
*
|
|
216
|
-
* assert.deepStrictEqual(fromIterable([1, 2, 3]), some(1))
|
|
217
|
-
* assert.deepStrictEqual(fromIterable([]), none())
|
|
215
|
+
* assert.deepStrictEqual(Option.fromIterable([1, 2, 3]), Option.some(1))
|
|
216
|
+
* assert.deepStrictEqual(Option.fromIterable([]), Option.none())
|
|
218
217
|
*
|
|
219
218
|
* @category constructors
|
|
220
219
|
* @since 2.0.0
|
|
@@ -226,11 +225,10 @@ export declare const fromIterable: <A>(collection: Iterable<A>) => Option<A>;
|
|
|
226
225
|
* Alias of {@link fromEither}.
|
|
227
226
|
*
|
|
228
227
|
* @example
|
|
229
|
-
* import
|
|
230
|
-
* import * as E from "effect/Either"
|
|
228
|
+
* import { Option, Either } from "effect"
|
|
231
229
|
*
|
|
232
|
-
* assert.deepStrictEqual(
|
|
233
|
-
* assert.deepStrictEqual(
|
|
230
|
+
* assert.deepStrictEqual(Option.getRight(Either.right('ok')), Option.some('ok'))
|
|
231
|
+
* assert.deepStrictEqual(Option.getRight(Either.left('err')), Option.none())
|
|
234
232
|
*
|
|
235
233
|
* @category conversions
|
|
236
234
|
* @since 2.0.0
|
|
@@ -240,11 +238,10 @@ export declare const getRight: <R, L>(self: Either<R, L>) => Option<R>;
|
|
|
240
238
|
* Converts a `Either` to an `Option` discarding the value.
|
|
241
239
|
*
|
|
242
240
|
* @example
|
|
243
|
-
* import
|
|
244
|
-
* import * as E from "effect/Either"
|
|
241
|
+
* import { Option, Either } from "effect"
|
|
245
242
|
*
|
|
246
|
-
* assert.deepStrictEqual(
|
|
247
|
-
* assert.deepStrictEqual(
|
|
243
|
+
* assert.deepStrictEqual(Option.getLeft(Either.right("ok")), Option.none())
|
|
244
|
+
* assert.deepStrictEqual(Option.getLeft(Either.left("a")), Option.some("a"))
|
|
248
245
|
*
|
|
249
246
|
* @category conversions
|
|
250
247
|
* @since 2.0.0
|
|
@@ -257,11 +254,10 @@ export declare const getLeft: <R, L>(self: Either<R, L>) => Option<L>;
|
|
|
257
254
|
* @param onNone - Function that returns the default value to return if the `Option` is `None`.
|
|
258
255
|
*
|
|
259
256
|
* @example
|
|
260
|
-
* import {
|
|
261
|
-
* import { pipe } from "effect/Function"
|
|
257
|
+
* import { pipe, Option } from "effect"
|
|
262
258
|
*
|
|
263
|
-
* assert.deepStrictEqual(pipe(some(1), getOrElse(() => 0)), 1)
|
|
264
|
-
* assert.deepStrictEqual(pipe(none(), getOrElse(() => 0)), 0)
|
|
259
|
+
* assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1)
|
|
260
|
+
* assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0)
|
|
265
261
|
*
|
|
266
262
|
* @category getters
|
|
267
263
|
* @since 2.0.0
|
|
@@ -277,36 +273,35 @@ export declare const getOrElse: {
|
|
|
277
273
|
* @param that - The `Option` to return if `self` is `None`.
|
|
278
274
|
*
|
|
279
275
|
* @example
|
|
280
|
-
* import
|
|
281
|
-
* import { pipe } from "effect/Function"
|
|
276
|
+
* import { pipe, Option } from "effect"
|
|
282
277
|
*
|
|
283
278
|
* assert.deepStrictEqual(
|
|
284
279
|
* pipe(
|
|
285
|
-
*
|
|
286
|
-
*
|
|
280
|
+
* Option.none(),
|
|
281
|
+
* Option.orElse(() => Option.none())
|
|
287
282
|
* ),
|
|
288
|
-
*
|
|
283
|
+
* Option.none()
|
|
289
284
|
* )
|
|
290
285
|
* assert.deepStrictEqual(
|
|
291
286
|
* pipe(
|
|
292
|
-
*
|
|
293
|
-
*
|
|
287
|
+
* Option.some('a'),
|
|
288
|
+
* Option.orElse(() => Option.none())
|
|
294
289
|
* ),
|
|
295
|
-
*
|
|
290
|
+
* Option.some('a')
|
|
296
291
|
* )
|
|
297
292
|
* assert.deepStrictEqual(
|
|
298
293
|
* pipe(
|
|
299
|
-
*
|
|
300
|
-
*
|
|
294
|
+
* Option.none(),
|
|
295
|
+
* Option.orElse(() => Option.some('b'))
|
|
301
296
|
* ),
|
|
302
|
-
*
|
|
297
|
+
* Option.some('b')
|
|
303
298
|
* )
|
|
304
299
|
* assert.deepStrictEqual(
|
|
305
300
|
* pipe(
|
|
306
|
-
*
|
|
307
|
-
*
|
|
301
|
+
* Option.some('a'),
|
|
302
|
+
* Option.orElse(() => Option.some('b'))
|
|
308
303
|
* ),
|
|
309
|
-
*
|
|
304
|
+
* Option.some('a')
|
|
310
305
|
* )
|
|
311
306
|
*
|
|
312
307
|
* @category error handling
|
|
@@ -323,22 +318,21 @@ export declare const orElse: {
|
|
|
323
318
|
* @param onNone - Function that returns the default value to return if the `Option` is `None`.
|
|
324
319
|
*
|
|
325
320
|
* @example
|
|
326
|
-
* import
|
|
327
|
-
* import { pipe } from "effect/Function"
|
|
321
|
+
* import { pipe, Option } from "effect"
|
|
328
322
|
*
|
|
329
323
|
* assert.deepStrictEqual(
|
|
330
324
|
* pipe(
|
|
331
|
-
*
|
|
332
|
-
*
|
|
325
|
+
* Option.none(),
|
|
326
|
+
* Option.orElseSome(() => 'b')
|
|
333
327
|
* ),
|
|
334
|
-
*
|
|
328
|
+
* Option.some('b')
|
|
335
329
|
* )
|
|
336
330
|
* assert.deepStrictEqual(
|
|
337
331
|
* pipe(
|
|
338
|
-
*
|
|
339
|
-
*
|
|
332
|
+
* Option.some('a'),
|
|
333
|
+
* Option.orElseSome(() => 'b')
|
|
340
334
|
* ),
|
|
341
|
-
*
|
|
335
|
+
* Option.some('a')
|
|
342
336
|
* )
|
|
343
337
|
*
|
|
344
338
|
* @category error handling
|
|
@@ -370,9 +364,9 @@ export declare const orElseEither: {
|
|
|
370
364
|
* @param collection - An iterable collection of `Option` to be searched.
|
|
371
365
|
*
|
|
372
366
|
* @example
|
|
373
|
-
* import
|
|
367
|
+
* import { Option } from "effect"
|
|
374
368
|
*
|
|
375
|
-
* assert.deepStrictEqual(
|
|
369
|
+
* assert.deepStrictEqual(Option.firstSomeOf([Option.none(), Option.some(1), Option.some(2)]), Option.some(1))
|
|
376
370
|
*
|
|
377
371
|
* @category error handling
|
|
378
372
|
* @since 2.0.0
|
|
@@ -385,11 +379,11 @@ export declare const firstSomeOf: <A>(collection: Iterable<Option<A>>) => Option
|
|
|
385
379
|
* @param nullableValue - The nullable value to be converted to an `Option`.
|
|
386
380
|
*
|
|
387
381
|
* @example
|
|
388
|
-
* import
|
|
382
|
+
* import { Option } from "effect"
|
|
389
383
|
*
|
|
390
|
-
* assert.deepStrictEqual(
|
|
391
|
-
* assert.deepStrictEqual(
|
|
392
|
-
* assert.deepStrictEqual(
|
|
384
|
+
* assert.deepStrictEqual(Option.fromNullable(undefined), Option.none())
|
|
385
|
+
* assert.deepStrictEqual(Option.fromNullable(null), Option.none())
|
|
386
|
+
* assert.deepStrictEqual(Option.fromNullable(1), Option.some(1))
|
|
393
387
|
*
|
|
394
388
|
* @category conversions
|
|
395
389
|
* @since 2.0.0
|
|
@@ -399,17 +393,17 @@ export declare const fromNullable: <A>(nullableValue: A) => Option<NonNullable<A
|
|
|
399
393
|
* This API is useful for lifting a function that returns `null` or `undefined` into the `Option` context.
|
|
400
394
|
*
|
|
401
395
|
* @example
|
|
402
|
-
* import
|
|
396
|
+
* import { Option } from "effect"
|
|
403
397
|
*
|
|
404
398
|
* const parse = (s: string): number | undefined => {
|
|
405
399
|
* const n = parseFloat(s)
|
|
406
400
|
* return isNaN(n) ? undefined : n
|
|
407
401
|
* }
|
|
408
402
|
*
|
|
409
|
-
* const parseOption =
|
|
403
|
+
* const parseOption = Option.liftNullable(parse)
|
|
410
404
|
*
|
|
411
|
-
* assert.deepStrictEqual(parseOption('1'),
|
|
412
|
-
* assert.deepStrictEqual(parseOption('not a number'),
|
|
405
|
+
* assert.deepStrictEqual(parseOption('1'), Option.some(1))
|
|
406
|
+
* assert.deepStrictEqual(parseOption('not a number'), Option.none())
|
|
413
407
|
*
|
|
414
408
|
* @category conversions
|
|
415
409
|
* @since 2.0.0
|
|
@@ -421,10 +415,10 @@ export declare const liftNullable: <A extends readonly unknown[], B>(f: (...a: A
|
|
|
421
415
|
* @param self - The `Option` to extract the value from.
|
|
422
416
|
*
|
|
423
417
|
* @example
|
|
424
|
-
* import
|
|
418
|
+
* import { Option } from "effect"
|
|
425
419
|
*
|
|
426
|
-
* assert.deepStrictEqual(
|
|
427
|
-
* assert.deepStrictEqual(
|
|
420
|
+
* assert.deepStrictEqual(Option.getOrNull(Option.some(1)), 1)
|
|
421
|
+
* assert.deepStrictEqual(Option.getOrNull(Option.none()), null)
|
|
428
422
|
*
|
|
429
423
|
* @category getters
|
|
430
424
|
* @since 2.0.0
|
|
@@ -436,10 +430,10 @@ export declare const getOrNull: <A>(self: Option<A>) => A | null;
|
|
|
436
430
|
* @param self - The `Option` to extract the value from.
|
|
437
431
|
*
|
|
438
432
|
* @example
|
|
439
|
-
* import
|
|
433
|
+
* import { Option } from "effect"
|
|
440
434
|
*
|
|
441
|
-
* assert.deepStrictEqual(
|
|
442
|
-
* assert.deepStrictEqual(
|
|
435
|
+
* assert.deepStrictEqual(Option.getOrUndefined(Option.some(1)), 1)
|
|
436
|
+
* assert.deepStrictEqual(Option.getOrUndefined(Option.none()), undefined)
|
|
443
437
|
*
|
|
444
438
|
* @category getters
|
|
445
439
|
* @since 2.0.0
|
|
@@ -454,12 +448,12 @@ export declare const getOrUndefined: <A>(self: Option<A>) => A | undefined;
|
|
|
454
448
|
* @param f - the function that can throw exceptions.
|
|
455
449
|
*
|
|
456
450
|
* @example
|
|
457
|
-
* import
|
|
451
|
+
* import { Option } from "effect"
|
|
458
452
|
*
|
|
459
|
-
* const parse =
|
|
453
|
+
* const parse = Option.liftThrowable(JSON.parse)
|
|
460
454
|
*
|
|
461
|
-
* assert.deepStrictEqual(parse("1"),
|
|
462
|
-
* assert.deepStrictEqual(parse(""),
|
|
455
|
+
* assert.deepStrictEqual(parse("1"), Option.some(1))
|
|
456
|
+
* assert.deepStrictEqual(parse(""), Option.none())
|
|
463
457
|
*
|
|
464
458
|
* @category conversions
|
|
465
459
|
* @since 2.0.0
|
|
@@ -474,13 +468,13 @@ export declare const liftThrowable: <A extends readonly unknown[], B>(f: (...a:
|
|
|
474
468
|
* @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.
|
|
475
469
|
*
|
|
476
470
|
* @example
|
|
477
|
-
* import
|
|
471
|
+
* import { Option } from "effect"
|
|
478
472
|
*
|
|
479
473
|
* assert.deepStrictEqual(
|
|
480
|
-
*
|
|
474
|
+
* Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),
|
|
481
475
|
* 1
|
|
482
476
|
* )
|
|
483
|
-
* assert.throws(() =>
|
|
477
|
+
* assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))
|
|
484
478
|
*
|
|
485
479
|
* @category conversions
|
|
486
480
|
* @since 2.0.0
|
|
@@ -498,10 +492,10 @@ export declare const getOrThrowWith: {
|
|
|
498
492
|
* @throws `Error("getOrThrow called on a None")`
|
|
499
493
|
*
|
|
500
494
|
* @example
|
|
501
|
-
* import
|
|
495
|
+
* import { Option } from "effect"
|
|
502
496
|
*
|
|
503
|
-
* assert.deepStrictEqual(
|
|
504
|
-
* assert.throws(() =>
|
|
497
|
+
* assert.deepStrictEqual(Option.getOrThrow(Option.some(1)), 1)
|
|
498
|
+
* assert.throws(() => Option.getOrThrow(Option.none()))
|
|
505
499
|
*
|
|
506
500
|
* @category conversions
|
|
507
501
|
* @since 2.0.0
|
|
@@ -574,8 +568,7 @@ export declare const andThen: {
|
|
|
574
568
|
* This is `flatMap` + `fromNullable`, useful when working with optional values.
|
|
575
569
|
*
|
|
576
570
|
* @example
|
|
577
|
-
* import {
|
|
578
|
-
* import { pipe } from "effect/Function"
|
|
571
|
+
* import { pipe, Option } from "effect"
|
|
579
572
|
*
|
|
580
573
|
* interface Employee {
|
|
581
574
|
* company?: {
|
|
@@ -591,20 +584,20 @@ export declare const andThen: {
|
|
|
591
584
|
*
|
|
592
585
|
* assert.deepStrictEqual(
|
|
593
586
|
* pipe(
|
|
594
|
-
* some(employee1),
|
|
595
|
-
* flatMapNullable(employee => employee.company?.address?.street?.name),
|
|
587
|
+
* Option.some(employee1),
|
|
588
|
+
* Option.flatMapNullable(employee => employee.company?.address?.street?.name),
|
|
596
589
|
* ),
|
|
597
|
-
* some('high street')
|
|
590
|
+
* Option.some('high street')
|
|
598
591
|
* )
|
|
599
592
|
*
|
|
600
593
|
* const employee2: Employee = { company: { address: { street: {} } } }
|
|
601
594
|
*
|
|
602
595
|
* assert.deepStrictEqual(
|
|
603
596
|
* pipe(
|
|
604
|
-
* some(employee2),
|
|
605
|
-
* flatMapNullable(employee => employee.company?.address?.street?.name),
|
|
597
|
+
* Option.some(employee2),
|
|
598
|
+
* Option.flatMapNullable(employee => employee.company?.address?.street?.name),
|
|
606
599
|
* ),
|
|
607
|
-
* none()
|
|
600
|
+
* Option.none()
|
|
608
601
|
* )
|
|
609
602
|
*
|
|
610
603
|
* @category sequencing
|
|
@@ -660,13 +653,13 @@ export declare const zipLeft: {
|
|
|
660
653
|
* @param self - The `Option` to apply the function to
|
|
661
654
|
*
|
|
662
655
|
* @example
|
|
663
|
-
* import
|
|
656
|
+
* import { Option } from "effect"
|
|
664
657
|
*
|
|
665
|
-
* const getInteger = (n: number) => Number.isInteger(n) ?
|
|
658
|
+
* const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()
|
|
666
659
|
*
|
|
667
|
-
* assert.deepStrictEqual(
|
|
668
|
-
* assert.deepStrictEqual(
|
|
669
|
-
* assert.deepStrictEqual(
|
|
660
|
+
* assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none())
|
|
661
|
+
* assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1))
|
|
662
|
+
* assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none())
|
|
670
663
|
*
|
|
671
664
|
* @category sequencing
|
|
672
665
|
* @since 2.0.0
|
|
@@ -695,11 +688,11 @@ export declare const productMany: <A>(self: Option<A>, collection: Iterable<Opti
|
|
|
695
688
|
* @param fields - the struct of `Option`s to be sequenced.
|
|
696
689
|
*
|
|
697
690
|
* @example
|
|
698
|
-
* import
|
|
691
|
+
* import { Option } from "effect"
|
|
699
692
|
*
|
|
700
|
-
* assert.deepStrictEqual(
|
|
701
|
-
* assert.deepStrictEqual(
|
|
702
|
-
* assert.deepStrictEqual(
|
|
693
|
+
* assert.deepStrictEqual(Option.all([Option.some(1), Option.some(2)]), Option.some([1, 2]))
|
|
694
|
+
* assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.some("hello") }), Option.some({ a: 1, b: "hello" }))
|
|
695
|
+
* assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.none() }), Option.none())
|
|
703
696
|
*
|
|
704
697
|
* @category combining
|
|
705
698
|
* @since 2.0.0
|
|
@@ -717,18 +710,18 @@ export declare const all: <const I extends Iterable<Option<any>> | Record<string
|
|
|
717
710
|
* @param f - The function used to combine the values of the two `Option`s
|
|
718
711
|
*
|
|
719
712
|
* @example
|
|
720
|
-
* import
|
|
713
|
+
* import { Option } from "effect"
|
|
721
714
|
*
|
|
722
715
|
* type Complex = [real: number, imaginary: number]
|
|
723
716
|
*
|
|
724
717
|
* const complex = (real: number, imaginary: number): Complex => [real, imaginary]
|
|
725
718
|
*
|
|
726
|
-
* assert.deepStrictEqual(
|
|
727
|
-
* assert.deepStrictEqual(
|
|
728
|
-
* assert.deepStrictEqual(
|
|
729
|
-
* assert.deepStrictEqual(
|
|
719
|
+
* assert.deepStrictEqual(Option.zipWith(Option.none(), Option.none(), complex), Option.none())
|
|
720
|
+
* assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.none(), complex), Option.none())
|
|
721
|
+
* assert.deepStrictEqual(Option.zipWith(Option.none(), Option.some(1), complex), Option.none())
|
|
722
|
+
* assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.some(2), complex), Option.some([1, 2]))
|
|
730
723
|
*
|
|
731
|
-
* assert.deepStrictEqual(
|
|
724
|
+
* assert.deepStrictEqual(Option.zipWith(Option.some(1), complex)(Option.some(2)), Option.some([2, 1]))
|
|
732
725
|
*
|
|
733
726
|
* @category zipping
|
|
734
727
|
* @since 2.0.0
|
|
@@ -753,11 +746,10 @@ export declare const ap: {
|
|
|
753
746
|
* @param f - The reducing function that takes the current accumulator value and the unwrapped value of an `Option<A>`.
|
|
754
747
|
*
|
|
755
748
|
* @example
|
|
756
|
-
* import {
|
|
757
|
-
* import { pipe } from "effect/Function"
|
|
749
|
+
* import { pipe, Option } from "effect"
|
|
758
750
|
*
|
|
759
|
-
* const iterable = [some(1), none(), some(2), none()]
|
|
760
|
-
* assert.deepStrictEqual(pipe(iterable, reduceCompact(0, (b, a) => b + a)), 3)
|
|
751
|
+
* const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]
|
|
752
|
+
* assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3)
|
|
761
753
|
*
|
|
762
754
|
* @category folding
|
|
763
755
|
* @since 2.0.0
|
|
@@ -774,10 +766,10 @@ export declare const reduceCompact: {
|
|
|
774
766
|
* @param self - The `Option` to convert to an array.
|
|
775
767
|
*
|
|
776
768
|
* @example
|
|
777
|
-
* import
|
|
769
|
+
* import { Option } from "effect"
|
|
778
770
|
*
|
|
779
|
-
* assert.deepStrictEqual(
|
|
780
|
-
* assert.deepStrictEqual(
|
|
771
|
+
* assert.deepStrictEqual(Option.toArray(Option.some(1)), [1])
|
|
772
|
+
* assert.deepStrictEqual(Option.toArray(Option.none()), [])
|
|
781
773
|
*
|
|
782
774
|
* @category conversions
|
|
783
775
|
* @since 2.0.0
|
|
@@ -800,13 +792,13 @@ export declare const partitionMap: {
|
|
|
800
792
|
* @param f - A function to apply to the value of the `Option`.
|
|
801
793
|
*
|
|
802
794
|
* @example
|
|
803
|
-
* import
|
|
795
|
+
* import { Option } from "effect"
|
|
804
796
|
*
|
|
805
|
-
* const evenNumber = (n: number) => n % 2 === 0 ?
|
|
797
|
+
* const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none()
|
|
806
798
|
*
|
|
807
|
-
* assert.deepStrictEqual(
|
|
808
|
-
* assert.deepStrictEqual(
|
|
809
|
-
* assert.deepStrictEqual(
|
|
799
|
+
* assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none())
|
|
800
|
+
* assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none())
|
|
801
|
+
* assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2))
|
|
810
802
|
*
|
|
811
803
|
* @category filtering
|
|
812
804
|
* @since 2.0.0
|
|
@@ -824,21 +816,21 @@ export declare const filterMap: {
|
|
|
824
816
|
* @param fb - The `Option` to filter.
|
|
825
817
|
*
|
|
826
818
|
* @example
|
|
827
|
-
* import
|
|
819
|
+
* import { Option } from "effect"
|
|
828
820
|
*
|
|
829
821
|
* // predicate
|
|
830
822
|
* const isEven = (n: number) => n % 2 === 0
|
|
831
823
|
*
|
|
832
|
-
* assert.deepStrictEqual(
|
|
833
|
-
* assert.deepStrictEqual(
|
|
834
|
-
* assert.deepStrictEqual(
|
|
824
|
+
* assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())
|
|
825
|
+
* assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())
|
|
826
|
+
* assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))
|
|
835
827
|
*
|
|
836
828
|
* // refinement
|
|
837
829
|
* const isNumber = (v: unknown): v is number => typeof v === "number"
|
|
838
830
|
*
|
|
839
|
-
* assert.deepStrictEqual(
|
|
840
|
-
* assert.deepStrictEqual(
|
|
841
|
-
* assert.deepStrictEqual(
|
|
831
|
+
* assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())
|
|
832
|
+
* assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())
|
|
833
|
+
* assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))
|
|
842
834
|
*
|
|
843
835
|
* @category filtering
|
|
844
836
|
* @since 2.0.0
|
|
@@ -851,15 +843,14 @@ export declare const filter: {
|
|
|
851
843
|
};
|
|
852
844
|
/**
|
|
853
845
|
* @example
|
|
854
|
-
* import {
|
|
855
|
-
* import * as N from 'effect/Number'
|
|
846
|
+
* import { Option, Number } from "effect"
|
|
856
847
|
*
|
|
857
|
-
* const isEquivalent = getEquivalence(
|
|
858
|
-
* assert.deepStrictEqual(isEquivalent(none(), none()), true)
|
|
859
|
-
* assert.deepStrictEqual(isEquivalent(none(), some(1)), false)
|
|
860
|
-
* assert.deepStrictEqual(isEquivalent(some(1), none()), false)
|
|
861
|
-
* assert.deepStrictEqual(isEquivalent(some(1), some(2)), false)
|
|
862
|
-
* assert.deepStrictEqual(isEquivalent(some(1), some(1)), true)
|
|
848
|
+
* const isEquivalent = Option.getEquivalence(Number.Equivalence)
|
|
849
|
+
* assert.deepStrictEqual(isEquivalent(Option.none(), Option.none()), true)
|
|
850
|
+
* assert.deepStrictEqual(isEquivalent(Option.none(), Option.some(1)), false)
|
|
851
|
+
* assert.deepStrictEqual(isEquivalent(Option.some(1), Option.none()), false)
|
|
852
|
+
* assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(2)), false)
|
|
853
|
+
* assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(1)), true)
|
|
863
854
|
*
|
|
864
855
|
* @category equivalence
|
|
865
856
|
* @since 2.0.0
|
|
@@ -873,16 +864,14 @@ export declare const getEquivalence: <A>(isEquivalent: Equivalence.Equivalence<A
|
|
|
873
864
|
* `None` is considered to be less than any `Some` value.
|
|
874
865
|
*
|
|
875
866
|
* @example
|
|
876
|
-
* import {
|
|
877
|
-
* import * as N from 'effect/Number'
|
|
878
|
-
* import { pipe } from "effect/Function"
|
|
867
|
+
* import { pipe, Option, Number } from "effect"
|
|
879
868
|
*
|
|
880
|
-
* const O = getOrder(
|
|
881
|
-
* assert.deepStrictEqual(O(none(), none()), 0)
|
|
882
|
-
* assert.deepStrictEqual(O(none(), some(1)), -1)
|
|
883
|
-
* assert.deepStrictEqual(O(some(1), none()), 1)
|
|
884
|
-
* assert.deepStrictEqual(O(some(1), some(2)), -1)
|
|
885
|
-
* assert.deepStrictEqual(O(some(1), some(1)), 0)
|
|
869
|
+
* const O = Option.getOrder(Number.Order)
|
|
870
|
+
* assert.deepStrictEqual(O(Option.none(), Option.none()), 0)
|
|
871
|
+
* assert.deepStrictEqual(O(Option.none(), Option.some(1)), -1)
|
|
872
|
+
* assert.deepStrictEqual(O(Option.some(1), Option.none()), 1)
|
|
873
|
+
* assert.deepStrictEqual(O(Option.some(1), Option.some(2)), -1)
|
|
874
|
+
* assert.deepStrictEqual(O(Option.some(1), Option.some(1)), 0)
|
|
886
875
|
*
|
|
887
876
|
* @category sorting
|
|
888
877
|
* @since 2.0.0
|
|
@@ -907,12 +896,12 @@ export declare const lift2: <A, B, C>(f: (a: A, b: B) => C) => {
|
|
|
907
896
|
* @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.
|
|
908
897
|
*
|
|
909
898
|
* @example
|
|
910
|
-
* import
|
|
899
|
+
* import { Option } from "effect"
|
|
911
900
|
*
|
|
912
|
-
* const getOption =
|
|
901
|
+
* const getOption = Option.liftPredicate((n: number) => n >= 0)
|
|
913
902
|
*
|
|
914
|
-
* assert.deepStrictEqual(getOption(-1),
|
|
915
|
-
* assert.deepStrictEqual(getOption(1),
|
|
903
|
+
* assert.deepStrictEqual(getOption(-1), Option.none())
|
|
904
|
+
* assert.deepStrictEqual(getOption(1), Option.some(1))
|
|
916
905
|
*
|
|
917
906
|
* @category lifting
|
|
918
907
|
* @since 2.0.0
|
|
@@ -929,13 +918,11 @@ export declare const liftPredicate: {
|
|
|
929
918
|
* @param a - The value to compare against the `Option`.
|
|
930
919
|
*
|
|
931
920
|
* @example
|
|
932
|
-
* import {
|
|
933
|
-
* import { Equivalence } from 'effect/Number'
|
|
934
|
-
* import { pipe } from "effect/Function"
|
|
921
|
+
* import { pipe, Option, Number } from "effect"
|
|
935
922
|
*
|
|
936
|
-
* assert.deepStrictEqual(pipe(some(2), containsWith(Equivalence)(2)), true)
|
|
937
|
-
* assert.deepStrictEqual(pipe(some(1), containsWith(Equivalence)(2)), false)
|
|
938
|
-
* assert.deepStrictEqual(pipe(none(), containsWith(Equivalence)(2)), false)
|
|
923
|
+
* assert.deepStrictEqual(pipe(Option.some(2), Option.containsWith(Number.Equivalence)(2)), true)
|
|
924
|
+
* assert.deepStrictEqual(pipe(Option.some(1), Option.containsWith(Number.Equivalence)(2)), false)
|
|
925
|
+
* assert.deepStrictEqual(pipe(Option.none(), Option.containsWith(Number.Equivalence)(2)), false)
|
|
939
926
|
*
|
|
940
927
|
* @category elements
|
|
941
928
|
* @since 2.0.0
|
|
@@ -961,14 +948,13 @@ export declare const contains: {
|
|
|
961
948
|
* @param predicate - The condition to check.
|
|
962
949
|
*
|
|
963
950
|
* @example
|
|
964
|
-
* import {
|
|
965
|
-
* import { pipe } from "effect/Function"
|
|
951
|
+
* import { pipe, Option } from "effect"
|
|
966
952
|
*
|
|
967
953
|
* const isEven = (n: number) => n % 2 === 0
|
|
968
954
|
*
|
|
969
|
-
* assert.deepStrictEqual(pipe(some(2), exists(isEven)), true)
|
|
970
|
-
* assert.deepStrictEqual(pipe(some(1), exists(isEven)), false)
|
|
971
|
-
* assert.deepStrictEqual(pipe(none(), exists(isEven)), false)
|
|
955
|
+
* assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)
|
|
956
|
+
* assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)
|
|
957
|
+
* assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)
|
|
972
958
|
*
|
|
973
959
|
* @since 2.0.0
|
|
974
960
|
*/
|
|
@@ -979,6 +965,32 @@ export declare const exists: {
|
|
|
979
965
|
<A>(self: Option<A>, predicate: Predicate<A>): boolean;
|
|
980
966
|
};
|
|
981
967
|
/**
|
|
968
|
+
* 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`.
|
|
969
|
+
*
|
|
970
|
+
* Here's how the do simulation works:
|
|
971
|
+
*
|
|
972
|
+
* 1. Start the do simulation using the `Do` value
|
|
973
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values
|
|
974
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
975
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
976
|
+
* 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
|
|
977
|
+
*
|
|
978
|
+
* @see {@link Do}
|
|
979
|
+
* @see {@link bind}
|
|
980
|
+
* @see {@link let_ let}
|
|
981
|
+
*
|
|
982
|
+
* @example
|
|
983
|
+
* import { Option, pipe } from "effect"
|
|
984
|
+
*
|
|
985
|
+
* const result = pipe(
|
|
986
|
+
* Option.Do,
|
|
987
|
+
* Option.bind("x", () => Option.some(2)),
|
|
988
|
+
* Option.bind("y", () => Option.some(3)),
|
|
989
|
+
* Option.let("sum", ({ x, y }) => x + y),
|
|
990
|
+
* Option.filter(({ x, y }) => x * y > 5)
|
|
991
|
+
* )
|
|
992
|
+
* assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))
|
|
993
|
+
*
|
|
982
994
|
* @category do notation
|
|
983
995
|
* @since 2.0.0
|
|
984
996
|
*/
|
|
@@ -1000,11 +1012,63 @@ declare const let_: {
|
|
|
1000
1012
|
};
|
|
1001
1013
|
export {
|
|
1002
1014
|
/**
|
|
1015
|
+
* 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`.
|
|
1016
|
+
*
|
|
1017
|
+
* Here's how the do simulation works:
|
|
1018
|
+
*
|
|
1019
|
+
* 1. Start the do simulation using the `Do` value
|
|
1020
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values
|
|
1021
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
1022
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
1023
|
+
* 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
|
|
1024
|
+
*
|
|
1025
|
+
* @see {@link Do}
|
|
1026
|
+
* @see {@link bind}
|
|
1027
|
+
* @see {@link bindTo}
|
|
1028
|
+
*
|
|
1029
|
+
* @example
|
|
1030
|
+
* import { Option, pipe } from "effect"
|
|
1031
|
+
*
|
|
1032
|
+
* const result = pipe(
|
|
1033
|
+
* Option.Do,
|
|
1034
|
+
* Option.bind("x", () => Option.some(2)),
|
|
1035
|
+
* Option.bind("y", () => Option.some(3)),
|
|
1036
|
+
* Option.let("sum", ({ x, y }) => x + y),
|
|
1037
|
+
* Option.filter(({ x, y }) => x * y > 5)
|
|
1038
|
+
* )
|
|
1039
|
+
* assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))
|
|
1040
|
+
*
|
|
1003
1041
|
* @category do notation
|
|
1004
1042
|
* @since 2.0.0
|
|
1005
1043
|
*/
|
|
1006
1044
|
let_ as let };
|
|
1007
1045
|
/**
|
|
1046
|
+
* 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`.
|
|
1047
|
+
*
|
|
1048
|
+
* Here's how the do simulation works:
|
|
1049
|
+
*
|
|
1050
|
+
* 1. Start the do simulation using the `Do` value
|
|
1051
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values
|
|
1052
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
1053
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
1054
|
+
* 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
|
|
1055
|
+
*
|
|
1056
|
+
* @see {@link Do}
|
|
1057
|
+
* @see {@link bindTo}
|
|
1058
|
+
* @see {@link let_ let}
|
|
1059
|
+
*
|
|
1060
|
+
* @example
|
|
1061
|
+
* import { Option, pipe } from "effect"
|
|
1062
|
+
*
|
|
1063
|
+
* const result = pipe(
|
|
1064
|
+
* Option.Do,
|
|
1065
|
+
* Option.bind("x", () => Option.some(2)),
|
|
1066
|
+
* Option.bind("y", () => Option.some(3)),
|
|
1067
|
+
* Option.let("sum", ({ x, y }) => x + y),
|
|
1068
|
+
* Option.filter(({ x, y }) => x * y > 5)
|
|
1069
|
+
* )
|
|
1070
|
+
* assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))
|
|
1071
|
+
*
|
|
1008
1072
|
* @category do notation
|
|
1009
1073
|
* @since 2.0.0
|
|
1010
1074
|
*/
|
|
@@ -1017,6 +1081,32 @@ export declare const bind: {
|
|
|
1017
1081
|
}>;
|
|
1018
1082
|
};
|
|
1019
1083
|
/**
|
|
1084
|
+
* 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`.
|
|
1085
|
+
*
|
|
1086
|
+
* Here's how the do simulation works:
|
|
1087
|
+
*
|
|
1088
|
+
* 1. Start the do simulation using the `Do` value
|
|
1089
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values
|
|
1090
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
1091
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
1092
|
+
* 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
|
|
1093
|
+
*
|
|
1094
|
+
* @see {@link bindTo}
|
|
1095
|
+
* @see {@link bind}
|
|
1096
|
+
* @see {@link let_ let}
|
|
1097
|
+
*
|
|
1098
|
+
* @example
|
|
1099
|
+
* import { Option, pipe } from "effect"
|
|
1100
|
+
*
|
|
1101
|
+
* const result = pipe(
|
|
1102
|
+
* Option.Do,
|
|
1103
|
+
* Option.bind("x", () => Option.some(2)),
|
|
1104
|
+
* Option.bind("y", () => Option.some(3)),
|
|
1105
|
+
* Option.let("sum", ({ x, y }) => x + y),
|
|
1106
|
+
* Option.filter(({ x, y }) => x * y > 5)
|
|
1107
|
+
* )
|
|
1108
|
+
* assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))
|
|
1109
|
+
*
|
|
1020
1110
|
* @category do notation
|
|
1021
1111
|
* @since 2.0.0
|
|
1022
1112
|
*/
|