effect 3.12.7 → 3.12.8

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.
Files changed (117) hide show
  1. package/dist/cjs/BigDecimal.js +1 -1
  2. package/dist/cjs/BigDecimal.js.map +1 -1
  3. package/dist/cjs/Cause.js +630 -167
  4. package/dist/cjs/Cause.js.map +1 -1
  5. package/dist/cjs/Chunk.js +4 -8
  6. package/dist/cjs/Chunk.js.map +1 -1
  7. package/dist/cjs/ConfigProvider.js +1 -0
  8. package/dist/cjs/ConfigProvider.js.map +1 -1
  9. package/dist/cjs/Cron.js +26 -10
  10. package/dist/cjs/Cron.js.map +1 -1
  11. package/dist/cjs/Duration.js +7 -4
  12. package/dist/cjs/Duration.js.map +1 -1
  13. package/dist/cjs/Effect.js.map +1 -1
  14. package/dist/cjs/Either.js +5 -24
  15. package/dist/cjs/Either.js.map +1 -1
  16. package/dist/cjs/Layer.js.map +1 -1
  17. package/dist/cjs/Option.js +1042 -363
  18. package/dist/cjs/Option.js.map +1 -1
  19. package/dist/cjs/ParseResult.js +41 -18
  20. package/dist/cjs/ParseResult.js.map +1 -1
  21. package/dist/cjs/Schedule.js +8 -1
  22. package/dist/cjs/Schedule.js.map +1 -1
  23. package/dist/cjs/Schema.js +51 -10
  24. package/dist/cjs/Schema.js.map +1 -1
  25. package/dist/cjs/internal/cause.js +23 -108
  26. package/dist/cjs/internal/cause.js.map +1 -1
  27. package/dist/cjs/internal/core.js +4 -5
  28. package/dist/cjs/internal/core.js.map +1 -1
  29. package/dist/cjs/internal/layer.js.map +1 -1
  30. package/dist/cjs/internal/schedule.js.map +1 -1
  31. package/dist/cjs/internal/secret.js +6 -5
  32. package/dist/cjs/internal/secret.js.map +1 -1
  33. package/dist/cjs/internal/stream.js +21 -23
  34. package/dist/cjs/internal/stream.js.map +1 -1
  35. package/dist/cjs/internal/version.js +1 -1
  36. package/dist/dts/BigDecimal.d.ts.map +1 -1
  37. package/dist/dts/Cause.d.ts +1157 -304
  38. package/dist/dts/Cause.d.ts.map +1 -1
  39. package/dist/dts/Chunk.d.ts +3 -6
  40. package/dist/dts/Chunk.d.ts.map +1 -1
  41. package/dist/dts/ConfigProvider.d.ts.map +1 -1
  42. package/dist/dts/Cron.d.ts +25 -9
  43. package/dist/dts/Cron.d.ts.map +1 -1
  44. package/dist/dts/Duration.d.ts +1 -1
  45. package/dist/dts/Duration.d.ts.map +1 -1
  46. package/dist/dts/Effect.d.ts +3 -2
  47. package/dist/dts/Effect.d.ts.map +1 -1
  48. package/dist/dts/Either.d.ts.map +1 -1
  49. package/dist/dts/Layer.d.ts +1 -1
  50. package/dist/dts/Layer.d.ts.map +1 -1
  51. package/dist/dts/Option.d.ts +2288 -784
  52. package/dist/dts/Option.d.ts.map +1 -1
  53. package/dist/dts/ParseResult.d.ts +4 -4
  54. package/dist/dts/ParseResult.d.ts.map +1 -1
  55. package/dist/dts/Schedule.d.ts +7 -0
  56. package/dist/dts/Schedule.d.ts.map +1 -1
  57. package/dist/dts/Schema.d.ts +15 -4
  58. package/dist/dts/Schema.d.ts.map +1 -1
  59. package/dist/dts/internal/core.d.ts.map +1 -1
  60. package/dist/dts/internal/stream.d.ts +1 -1
  61. package/dist/dts/internal/stream.d.ts.map +1 -1
  62. package/dist/esm/BigDecimal.js +1 -1
  63. package/dist/esm/BigDecimal.js.map +1 -1
  64. package/dist/esm/Cause.js +630 -167
  65. package/dist/esm/Cause.js.map +1 -1
  66. package/dist/esm/Chunk.js +4 -8
  67. package/dist/esm/Chunk.js.map +1 -1
  68. package/dist/esm/ConfigProvider.js +1 -0
  69. package/dist/esm/ConfigProvider.js.map +1 -1
  70. package/dist/esm/Cron.js +27 -11
  71. package/dist/esm/Cron.js.map +1 -1
  72. package/dist/esm/Duration.js +7 -4
  73. package/dist/esm/Duration.js.map +1 -1
  74. package/dist/esm/Effect.js.map +1 -1
  75. package/dist/esm/Either.js +5 -24
  76. package/dist/esm/Either.js.map +1 -1
  77. package/dist/esm/Layer.js.map +1 -1
  78. package/dist/esm/Option.js +1041 -363
  79. package/dist/esm/Option.js.map +1 -1
  80. package/dist/esm/ParseResult.js +41 -18
  81. package/dist/esm/ParseResult.js.map +1 -1
  82. package/dist/esm/Schedule.js +7 -0
  83. package/dist/esm/Schedule.js.map +1 -1
  84. package/dist/esm/Schema.js +51 -10
  85. package/dist/esm/Schema.js.map +1 -1
  86. package/dist/esm/internal/cause.js +22 -108
  87. package/dist/esm/internal/cause.js.map +1 -1
  88. package/dist/esm/internal/core.js +4 -5
  89. package/dist/esm/internal/core.js.map +1 -1
  90. package/dist/esm/internal/layer.js.map +1 -1
  91. package/dist/esm/internal/schedule.js.map +1 -1
  92. package/dist/esm/internal/secret.js +5 -4
  93. package/dist/esm/internal/secret.js.map +1 -1
  94. package/dist/esm/internal/stream.js +21 -23
  95. package/dist/esm/internal/stream.js.map +1 -1
  96. package/dist/esm/internal/version.js +1 -1
  97. package/package.json +1 -1
  98. package/src/BigDecimal.ts +1 -1
  99. package/src/Cause.ts +1158 -304
  100. package/src/Chunk.ts +8 -11
  101. package/src/ConfigProvider.ts +1 -0
  102. package/src/Cron.ts +28 -11
  103. package/src/Duration.ts +10 -5
  104. package/src/Effect.ts +5 -2
  105. package/src/Either.ts +11 -28
  106. package/src/Layer.ts +1 -1
  107. package/src/Option.ts +2314 -820
  108. package/src/ParseResult.ts +53 -29
  109. package/src/Schedule.ts +8 -0
  110. package/src/Schema.ts +68 -12
  111. package/src/internal/cause.ts +38 -137
  112. package/src/internal/core.ts +4 -5
  113. package/src/internal/layer.ts +1 -1
  114. package/src/internal/schedule.ts +7 -6
  115. package/src/internal/secret.ts +6 -4
  116. package/src/internal/stream.ts +24 -37
  117. package/src/internal/version.ts +1 -1
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.zipWith = exports.zipRight = exports.zipLeft = exports.void = exports.toRefinement = exports.toArray = exports.tap = exports.some = exports.reduceCompact = exports.productMany = exports.product = exports.partitionMap = exports.orElseSome = exports.orElseEither = exports.orElse = exports.none = exports.match = exports.map = exports.liftThrowable = exports.liftPredicate = exports.liftNullable = exports.lift2 = exports.let = exports.isSome = exports.isOption = exports.isNone = exports.getRight = exports.getOrder = exports.getOrUndefined = exports.getOrThrowWith = exports.getOrThrow = exports.getOrNull = exports.getOrElse = exports.getLeft = exports.getEquivalence = exports.gen = exports.fromNullable = exports.fromIterable = exports.flatten = exports.flatMapNullable = exports.flatMap = exports.firstSomeOf = exports.filterMap = exports.filter = exports.exists = exports.containsWith = exports.contains = exports.composeK = exports.bindTo = exports.bind = exports.asVoid = exports.as = exports.ap = exports.andThen = exports.all = exports.TypeId = exports.Do = void 0;
6
+ exports.zipWith = exports.zipRight = exports.zipLeft = exports.void = exports.toRefinement = exports.toArray = exports.tap = exports.some = exports.reduceCompact = exports.productMany = exports.product = exports.partitionMap = exports.orElseSome = exports.orElseEither = exports.orElse = exports.none = exports.mergeWith = exports.match = exports.map = exports.liftThrowable = exports.liftPredicate = exports.liftNullable = exports.lift2 = exports.let = exports.isSome = exports.isOption = exports.isNone = exports.getRight = exports.getOrder = exports.getOrUndefined = exports.getOrThrowWith = exports.getOrThrow = exports.getOrNull = exports.getOrElse = exports.getLeft = exports.getEquivalence = exports.gen = exports.fromNullable = exports.fromIterable = exports.flatten = exports.flatMapNullable = exports.flatMap = exports.firstSomeOf = exports.filterMap = exports.filter = exports.exists = exports.containsWith = exports.contains = exports.composeK = exports.bindTo = exports.bind = exports.asVoid = exports.as = exports.ap = exports.andThen = exports.all = exports.TypeId = exports.Do = void 0;
7
7
  var Equal = _interopRequireWildcard(require("./Equal.js"));
8
8
  var Equivalence = _interopRequireWildcard(require("./Equivalence.js"));
9
9
  var _Function = require("./Function.js");
@@ -15,103 +15,168 @@ var Gen = _interopRequireWildcard(require("./Utils.js"));
15
15
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
16
16
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
17
17
  /**
18
- * @category symbols
18
+ * @category Symbols
19
19
  * @since 2.0.0
20
20
  */
21
21
  const TypeId = exports.TypeId = /*#__PURE__*/Symbol.for("effect/Option");
22
22
  /**
23
- * Creates a new `Option` that represents the absence of a value.
23
+ * Represents the absence of a value by creating an empty `Option`.
24
24
  *
25
- * @category constructors
25
+ * `Option.none` returns an `Option<never>`, which is a subtype of `Option<A>`.
26
+ * This means you can use it in place of any `Option<A>` regardless of the type
27
+ * `A`.
28
+ *
29
+ * @see {@link some} for the opposite operation.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * // Title: Creating an Option with No Value
34
+ * import { Option } from "effect"
35
+ *
36
+ * // An Option holding no value
37
+ * //
38
+ * // ┌─── Option<never>
39
+ * // ▼
40
+ * const noValue = Option.none()
41
+ *
42
+ * console.log(noValue)
43
+ * // Output: { _id: 'Option', _tag: 'None' }
44
+ * ```
45
+ *
46
+ * @category Constructors
26
47
  * @since 2.0.0
27
48
  */
28
49
  const none = () => option.none;
29
50
  /**
30
- * Creates a new `Option` that wraps the given value.
51
+ * Wraps the given value into an `Option` to represent its presence.
31
52
  *
32
- * @param value - The value to wrap.
53
+ * @see {@link none} for the opposite operation.
33
54
  *
34
- * @category constructors
55
+ * @example
56
+ * ```ts
57
+ * // Title: Creating an Option with a Value
58
+ * import { Option } from "effect"
59
+ *
60
+ * // An Option holding the number 1
61
+ * //
62
+ * // ┌─── Option<number>
63
+ * // ▼
64
+ * const value = Option.some(1)
65
+ *
66
+ * console.log(value)
67
+ * // Output: { _id: 'Option', _tag: 'Some', value: 1 }
68
+ * ```
69
+ *
70
+ * @category Constructors
35
71
  * @since 2.0.0
36
72
  */
37
73
  exports.none = none;
38
74
  const some = exports.some = option.some;
39
75
  /**
40
- * Checks if a given value is an `Option` value.
76
+ * Determines whether the given value is an `Option`.
41
77
  *
42
- * @param input - The value to check.
78
+ * **Details**
79
+ *
80
+ * This function checks if a value is an instance of `Option`. It returns `true`
81
+ * if the value is either `Option.some` or `Option.none`, and `false` otherwise.
82
+ * This is particularly useful when working with unknown values or when you need
83
+ * to ensure type safety in your code.
43
84
  *
44
85
  * @example
45
86
  * ```ts
46
87
  * import { Option } from "effect"
47
88
  *
48
- * assert.deepStrictEqual(Option.isOption(Option.some(1)), true)
49
- * assert.deepStrictEqual(Option.isOption(Option.none()), true)
50
- * assert.deepStrictEqual(Option.isOption({}), false)
89
+ * console.log(Option.isOption(Option.some(1)))
90
+ * // Output: true
91
+ *
92
+ * console.log(Option.isOption(Option.none()))
93
+ * // Output: true
94
+ *
95
+ * console.log(Option.isOption({}))
96
+ * // Output: false
51
97
  * ```
52
98
  *
53
- * @category guards
99
+ * @category Guards
54
100
  * @since 2.0.0
55
101
  */
56
102
  const isOption = exports.isOption = option.isOption;
57
103
  /**
58
- * Determine if a `Option` is a `None`.
104
+ * Checks whether an `Option` represents the absence of a value (`None`).
59
105
  *
60
- * @param self - The `Option` to check.
106
+ * @see {@link isSome} for the opposite check.
61
107
  *
62
108
  * @example
63
109
  * ```ts
64
110
  * import { Option } from "effect"
65
111
  *
66
- * assert.deepStrictEqual(Option.isNone(Option.some(1)), false)
67
- * assert.deepStrictEqual(Option.isNone(Option.none()), true)
112
+ * console.log(Option.isNone(Option.some(1)))
113
+ * // Output: false
114
+ *
115
+ * console.log(Option.isNone(Option.none()))
116
+ * // Output: true
68
117
  * ```
69
118
  *
70
- * @category guards
119
+ * @category Guards
71
120
  * @since 2.0.0
72
121
  */
73
122
  const isNone = exports.isNone = option.isNone;
74
123
  /**
75
- * Determine if a `Option` is a `Some`.
124
+ * Checks whether an `Option` contains a value (`Some`).
76
125
  *
77
- * @param self - The `Option` to check.
126
+ * @see {@link isNone} for the opposite check.
78
127
  *
79
128
  * @example
80
129
  * ```ts
81
130
  * import { Option } from "effect"
82
131
  *
83
- * assert.deepStrictEqual(Option.isSome(Option.some(1)), true)
84
- * assert.deepStrictEqual(Option.isSome(Option.none()), false)
132
+ * console.log(Option.isSome(Option.some(1)))
133
+ * // Output: true
134
+ *
135
+ * console.log(Option.isSome(Option.none()))
136
+ * // Output: false
85
137
  * ```
86
138
  *
87
- * @category guards
139
+ * @category Guards
88
140
  * @since 2.0.0
89
141
  */
90
142
  const isSome = exports.isSome = option.isSome;
91
143
  /**
92
- * Matches the given `Option` and returns either the provided `onNone` value or the result of the provided `onSome`
93
- * function when passed the `Option`'s value.
144
+ * Performs pattern matching on an `Option` to handle both `Some` and `None`
145
+ * cases.
146
+ *
147
+ * **Details**
148
+ *
149
+ * This function allows you to match against an `Option` and handle both
150
+ * scenarios: when the `Option` is `None` (i.e., contains no value), and when
151
+ * the `Option` is `Some` (i.e., contains a value). It executes one of the
152
+ * provided functions based on the case:
94
153
  *
95
- * @param self - The `Option` to match
96
- * @param onNone - The value to be returned if the `Option` is `None`
97
- * @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
154
+ * - If the `Option` is `None`, the `onNone` function is executed and its result
155
+ * is returned.
156
+ * - If the `Option` is `Some`, the `onSome` function is executed with the
157
+ * contained value, and its result is returned.
158
+ *
159
+ * This function provides a concise and functional way to handle optional values
160
+ * without resorting to `if` or manual checks, making your code more declarative
161
+ * and readable.
98
162
  *
99
163
  * @example
100
164
  * ```ts
101
- * import { pipe, Option } from "effect"
165
+ * // Title: Pattern Matching with Option
166
+ * import { Option } from "effect"
102
167
  *
103
- * assert.deepStrictEqual(
104
- * pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),
105
- * 'a some containing 1'
106
- * )
168
+ * const foo = Option.some(1)
107
169
  *
108
- * assert.deepStrictEqual(
109
- * pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),
110
- * 'a none'
111
- * )
170
+ * const message = Option.match(foo, {
171
+ * onNone: () => "Option is empty",
172
+ * onSome: (value) => `Option has a value: ${value}`
173
+ * })
174
+ *
175
+ * console.log(message)
176
+ * // Output: "Option has a value: 1"
112
177
  * ```
113
178
  *
114
- * @category pattern matching
179
+ * @category Pattern matching
115
180
  * @since 2.0.0
116
181
  */
117
182
  const match = exports.match = /*#__PURE__*/(0, _Function.dual)(2, (self, {
@@ -119,41 +184,76 @@ const match = exports.match = /*#__PURE__*/(0, _Function.dual)(2, (self, {
119
184
  onSome
120
185
  }) => isNone(self) ? onNone() : onSome(self.value));
121
186
  /**
122
- * Returns a type guard from a `Option` returning function.
123
- * This function ensures that a type guard definition is type-safe.
187
+ * Converts an `Option`-returning function into a type guard.
188
+ *
189
+ * **Details**
190
+ *
191
+ * This function transforms a function that returns an `Option` into a type
192
+ * guard, ensuring type safety when validating or narrowing types. The returned
193
+ * type guard function checks whether the input satisfies the condition defined
194
+ * in the original `Option`-returning function.
195
+ *
196
+ * If the original function returns `Option.some`, the type guard evaluates to
197
+ * `true`, confirming the input is of the desired type. If the function returns
198
+ * `Option.none`, the type guard evaluates to `false`.
199
+ *
200
+ * This utility is especially useful for validating types in union types,
201
+ * filtering arrays, or ensuring safe handling of specific subtypes.
124
202
  *
125
203
  * @example
126
204
  * ```ts
127
205
  * import { Option } from "effect"
128
206
  *
129
- * const parsePositive = (n: number): Option.Option<number> =>
130
- * n > 0 ? Option.some(n) : Option.none()
207
+ * type MyData = string | number
208
+ *
209
+ * const parseString = (data: MyData): Option.Option<string> =>
210
+ * typeof data === "string" ? Option.some(data) : Option.none()
131
211
  *
132
- * const isPositive = Option.toRefinement(parsePositive)
212
+ * // ┌─── (a: MyData) => a is string
213
+ * // ▼
214
+ * const isString = Option.toRefinement(parseString)
133
215
  *
134
- * assert.deepStrictEqual(isPositive(1), true)
135
- * assert.deepStrictEqual(isPositive(-1), false)
216
+ * console.log(isString("a"))
217
+ * // Output: true
218
+ *
219
+ * console.log(isString(1))
220
+ * // Output: false
136
221
  * ```
137
222
  *
138
- * @category conversions
223
+ * @category Conversions
139
224
  * @since 2.0.0
140
225
  */
141
226
  const toRefinement = f => a => isSome(f(a));
142
227
  /**
143
- * Converts an `Iterable` of values into an `Option`. Returns the first value of the `Iterable` wrapped in a `Some`
144
- * if the `Iterable` is not empty, otherwise returns `None`.
228
+ * Converts an `Iterable` into an `Option`, wrapping the first element if it
229
+ * exists.
230
+ *
231
+ * **Details**
232
+ *
233
+ * This function takes an `Iterable` (e.g., an array, a generator, or any object
234
+ * implementing the `Iterable` interface) and returns an `Option` based on its
235
+ * content:
145
236
  *
146
- * @param collection - The `Iterable` to be converted to an `Option`.
237
+ * - If the `Iterable` contains at least one element, the first element is
238
+ * wrapped in a `Some` and returned.
239
+ * - If the `Iterable` is empty, `None` is returned, representing the absence of
240
+ * a value.
241
+ *
242
+ * This utility is useful for safely handling collections that might be empty,
243
+ * ensuring you explicitly handle both cases where a value exists or doesn't.
147
244
  *
148
245
  * @example
149
246
  * ```ts
150
247
  * import { Option } from "effect"
151
248
  *
152
- * assert.deepStrictEqual(Option.fromIterable([1, 2, 3]), Option.some(1))
153
- * assert.deepStrictEqual(Option.fromIterable([]), Option.none())
249
+ * console.log(Option.fromIterable([1, 2, 3]))
250
+ * // Output: { _id: 'Option', _tag: 'Some', value: 1 }
251
+ *
252
+ * console.log(Option.fromIterable([]))
253
+ * // Output: { _id: 'Option', _tag: 'None' }
154
254
  * ```
155
255
  *
156
- * @category constructors
256
+ * @category Constructors
157
257
  * @since 2.0.0
158
258
  */
159
259
  exports.toRefinement = toRefinement;
@@ -164,154 +264,227 @@ const fromIterable = collection => {
164
264
  return none();
165
265
  };
166
266
  /**
167
- * Converts a `Either` to an `Option` discarding the error.
267
+ * Converts an `Either` into an `Option` by discarding the error and extracting
268
+ * the right value.
269
+ *
270
+ * **Details**
271
+ *
272
+ * This function takes an `Either` and returns an `Option` based on its value:
273
+ *
274
+ * - If the `Either` is a `Right`, its value is wrapped in a `Some` and
275
+ * returned.
276
+ * - If the `Either` is a `Left`, the error is discarded, and `None` is
277
+ * returned.
278
+ *
279
+ * This is particularly useful when you only care about the success case
280
+ * (`Right`) of an `Either` and want to handle the result using `Option`. By
281
+ * using this function, you can convert `Either` into a simpler structure for
282
+ * cases where error handling is not required.
283
+ *
284
+ * @see {@link getLeft} for the opposite operation.
168
285
  *
169
286
  * @example
170
287
  * ```ts
171
- * import { Option, Either } from "effect"
288
+ * import { Either, Option } from "effect"
289
+ *
290
+ * console.log(Option.getRight(Either.right("ok")))
291
+ * // Output: { _id: 'Option', _tag: 'Some', value: 'ok' }
172
292
  *
173
- * assert.deepStrictEqual(Option.getRight(Either.right('ok')), Option.some('ok'))
174
- * assert.deepStrictEqual(Option.getRight(Either.left('err')), Option.none())
293
+ * console.log(Option.getRight(Either.left("err")))
294
+ * // Output: { _id: 'Option', _tag: 'None' }
175
295
  * ```
176
296
  *
177
- * @category conversions
297
+ * @category Conversions
178
298
  * @since 2.0.0
179
299
  */
180
300
  exports.fromIterable = fromIterable;
181
301
  const getRight = exports.getRight = either.getRight;
182
302
  /**
183
- * Converts a `Either` to an `Option` discarding the value.
303
+ * Converts an `Either` into an `Option` by discarding the right value and
304
+ * extracting the left value.
305
+ *
306
+ * **Details**
307
+ *
308
+ * This function transforms an `Either` into an `Option` as follows:
309
+ *
310
+ * - If the `Either` is a `Left`, its value is wrapped in a `Some` and returned.
311
+ * - If the `Either` is a `Right`, the value is discarded, and `None` is
312
+ * returned.
313
+ *
314
+ * This utility is useful when you only care about the error case (`Left`) of an
315
+ * `Either` and want to handle it as an `Option`. By discarding the right value,
316
+ * it simplifies error-focused workflows.
317
+ *
318
+ * @see {@link getRight} for the opposite operation.
184
319
  *
185
320
  * @example
186
321
  * ```ts
187
- * import { Option, Either } from "effect"
322
+ * import { Either, Option } from "effect"
188
323
  *
189
- * assert.deepStrictEqual(Option.getLeft(Either.right("ok")), Option.none())
190
- * assert.deepStrictEqual(Option.getLeft(Either.left("a")), Option.some("a"))
324
+ * console.log(Option.getLeft(Either.right("ok")))
325
+ * // Output: { _id: 'Option', _tag: 'None' }
326
+ *
327
+ * console.log(Option.getLeft(Either.left("err")))
328
+ * // Output: { _id: 'Option', _tag: 'Some', value: 'err' }
191
329
  * ```
192
330
  *
193
- * @category conversions
331
+ * @category Conversions
194
332
  * @since 2.0.0
195
333
  */
196
334
  const getLeft = exports.getLeft = either.getLeft;
197
335
  /**
198
- * Returns the value of the `Option` if it is `Some`, otherwise returns `onNone`
336
+ * Returns the value contained in the `Option` if it is `Some`, otherwise
337
+ * evaluates and returns the result of `onNone`.
338
+ *
339
+ * **Details**
199
340
  *
200
- * @param self - The `Option` to get the value of.
201
- * @param onNone - Function that returns the default value to return if the `Option` is `None`.
341
+ * This function allows you to provide a fallback value or computation for when
342
+ * an `Option` is `None`. If the `Option` contains a value (`Some`), that value
343
+ * is returned. If it is empty (`None`), the `onNone` function is executed, and
344
+ * its result is returned instead.
345
+ *
346
+ * This utility is helpful for safely handling `Option` values by ensuring you
347
+ * always receive a meaningful result, whether or not the `Option` contains a
348
+ * value. It is particularly useful for providing default values or alternative
349
+ * logic when working with optional values.
350
+ *
351
+ * @see {@link getOrNull} for a version that returns `null` instead of executing a function.
352
+ * @see {@link getOrUndefined} for a version that returns `undefined` instead of executing a function.
202
353
  *
203
354
  * @example
204
355
  * ```ts
205
- * import { pipe, Option } from "effect"
356
+ * import { Option } from "effect"
206
357
  *
207
- * assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1)
208
- * assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0)
358
+ * console.log(Option.some(1).pipe(Option.getOrElse(() => 0)))
359
+ * // Output: 1
360
+ *
361
+ * console.log(Option.none().pipe(Option.getOrElse(() => 0)))
362
+ * // Output: 0
209
363
  * ```
210
364
  *
211
- * @category getters
365
+ * @category Getters
212
366
  * @since 2.0.0
213
367
  */
214
368
  const getOrElse = exports.getOrElse = /*#__PURE__*/(0, _Function.dual)(2, (self, onNone) => isNone(self) ? onNone() : self.value);
215
369
  /**
216
- * Returns the provided `Option` `that` if `self` is `None`, otherwise returns `self`.
370
+ * Returns the provided `Option` `that` if the current `Option` (`self`) is
371
+ * `None`; otherwise, it returns `self`.
372
+ *
373
+ * **Details**
217
374
  *
218
- * @param self - The first `Option` to be checked.
219
- * @param that - The `Option` to return if `self` is `None`.
375
+ * This function provides a fallback mechanism for `Option` values. If the
376
+ * current `Option` is `None` (i.e., it contains no value), the `that` function
377
+ * is evaluated, and its resulting `Option` is returned. If the current `Option`
378
+ * is `Some` (i.e., it contains a value), the original `Option` is returned
379
+ * unchanged.
380
+ *
381
+ * This is particularly useful for chaining fallback values or computations,
382
+ * allowing you to provide alternative `Option` values when the first one is
383
+ * empty.
220
384
  *
221
385
  * @example
222
386
  * ```ts
223
- * import { pipe, Option } from "effect"
387
+ * import { Option } from "effect"
224
388
  *
225
- * assert.deepStrictEqual(
226
- * pipe(
227
- * Option.none(),
228
- * Option.orElse(() => Option.none())
229
- * ),
230
- * Option.none()
231
- * )
232
- * assert.deepStrictEqual(
233
- * pipe(
234
- * Option.some('a'),
235
- * Option.orElse(() => Option.none())
236
- * ),
237
- * Option.some('a')
238
- * )
239
- * assert.deepStrictEqual(
240
- * pipe(
241
- * Option.none(),
242
- * Option.orElse(() => Option.some('b'))
243
- * ),
244
- * Option.some('b')
245
- * )
246
- * assert.deepStrictEqual(
247
- * pipe(
248
- * Option.some('a'),
249
- * Option.orElse(() => Option.some('b'))
250
- * ),
251
- * Option.some('a')
252
- * )
389
+ * console.log(Option.none().pipe(Option.orElse(() => Option.none())))
390
+ * // Output: { _id: 'Option', _tag: 'None' }
391
+ *
392
+ * console.log(Option.some("a").pipe(Option.orElse(() => Option.none())))
393
+ * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }
394
+ *
395
+ * console.log(Option.none().pipe(Option.orElse(() => Option.some("b"))))
396
+ * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }
397
+ *
398
+ * console.log(Option.some("a").pipe(Option.orElse(() => Option.some("b"))))
399
+ * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }
253
400
  * ```
254
401
  *
255
- * @category error handling
402
+ * @category Error handling
256
403
  * @since 2.0.0
257
404
  */
258
405
  const orElse = exports.orElse = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => isNone(self) ? that() : self);
259
406
  /**
260
- * Returns the provided default value as `Some` if `self` is `None`, otherwise returns `self`.
407
+ * Returns the provided default value wrapped in `Some` if the current `Option`
408
+ * (`self`) is `None`; otherwise, returns `self`.
409
+ *
410
+ * **Details**
411
+ *
412
+ * This function provides a way to supply a default value for cases where an
413
+ * `Option` is `None`. If the current `Option` is empty (`None`), the `onNone`
414
+ * function is executed to compute the default value, which is then wrapped in a
415
+ * `Some`. If the current `Option` contains a value (`Some`), it is returned as
416
+ * is.
261
417
  *
262
- * @param self - The first `Option` to be checked.
263
- * @param onNone - Function that returns the default value to return if the `Option` is `None`.
418
+ * This is particularly useful for handling optional values where a fallback
419
+ * default needs to be provided explicitly in case of absence.
264
420
  *
265
421
  * @example
266
422
  * ```ts
267
- * import { pipe, Option } from "effect"
423
+ * import { Option } from "effect"
268
424
  *
269
- * assert.deepStrictEqual(
270
- * pipe(
271
- * Option.none(),
272
- * Option.orElseSome(() => 'b')
273
- * ),
274
- * Option.some('b')
275
- * )
276
- * assert.deepStrictEqual(
277
- * pipe(
278
- * Option.some('a'),
279
- * Option.orElseSome(() => 'b')
280
- * ),
281
- * Option.some('a')
282
- * )
425
+ * console.log(Option.none().pipe(Option.orElseSome(() => "b")))
426
+ * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }
427
+ *
428
+ * console.log(Option.some("a").pipe(Option.orElseSome(() => "b")))
429
+ * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }
283
430
  * ```
284
431
  *
285
- * @category error handling
432
+ * @category Error handling
286
433
  * @since 2.0.0
287
434
  */
288
435
  const orElseSome = exports.orElseSome = /*#__PURE__*/(0, _Function.dual)(2, (self, onNone) => isNone(self) ? some(onNone()) : self);
289
436
  /**
290
- * Similar to `orElse`, but instead of returning a simple union, it returns an `Either` object,
291
- * which contains information about which of the two `Option`s has been chosen.
437
+ * Similar to {@link orElse}, but returns an `Either` wrapped in an `Option` to
438
+ * indicate the source of the value.
292
439
  *
293
- * This is useful when it's important to know whether the value was retrieved from the first `Option` or the second option.
440
+ * **Details**
294
441
  *
295
- * @param self - The first `Option` to be checked.
296
- * @param that - The second `Option` to be considered if the first `Option` is `None`.
442
+ * This function allows you to provide a fallback `Option` in case the current
443
+ * `Option` (`self`) is `None`. However, unlike `orElse`, it returns the value
444
+ * wrapped in an `Either` object, providing additional information about where
445
+ * the value came from:
297
446
  *
298
- * @category error handling
447
+ * - If the value is from the fallback `Option` (`that`), it is wrapped in an
448
+ * `Either.right`.
449
+ * - If the value is from the original `Option` (`self`), it is wrapped in an
450
+ * `Either.left`.
451
+ *
452
+ * This is especially useful when you need to differentiate between values
453
+ * originating from the primary `Option` and those coming from the fallback,
454
+ * while still maintaining the `Option`-style handling.
455
+ *
456
+ * @category Error handling
299
457
  * @since 2.0.0
300
458
  */
301
459
  const orElseEither = exports.orElseEither = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => isNone(self) ? map(that(), either.right) : map(self, either.left));
302
460
  /**
303
- * Given an `Iterable` collection of `Option`s, returns the first `Some` found in the collection.
461
+ * Returns the first `Some` value found in an `Iterable` collection of
462
+ * `Option`s, or `None` if no `Some` is found.
463
+ *
464
+ * **Details**
304
465
  *
305
- * @param collection - An iterable collection of `Option` to be searched.
466
+ * This function iterates over a collection of `Option` values and returns the
467
+ * first `Some` it encounters. If the collection contains only `None` values,
468
+ * the result will also be `None`. This utility is useful for efficiently
469
+ * finding the first valid value in a sequence of potentially empty or invalid
470
+ * options.
471
+ *
472
+ * The iteration stops as soon as a `Some` is found, making this function
473
+ * efficient for large collections.
306
474
  *
307
475
  * @example
308
476
  * ```ts
309
477
  * import { Option } from "effect"
310
478
  *
311
- * assert.deepStrictEqual(Option.firstSomeOf([Option.none(), Option.some(1), Option.some(2)]), Option.some(1))
479
+ * console.log(Option.firstSomeOf([
480
+ * Option.none(),
481
+ * Option.some(1),
482
+ * Option.some(2)
483
+ * ]))
484
+ * // Output: { _id: 'Option', _tag: 'Some', value: 1 }
312
485
  * ```
313
486
  *
314
- * @category error handling
487
+ * @category Error handling
315
488
  * @since 2.0.0
316
489
  */
317
490
  const firstSomeOf = collection => {
@@ -324,27 +497,39 @@ const firstSomeOf = collection => {
324
497
  return out;
325
498
  };
326
499
  /**
327
- * Constructs a new `Option` from a nullable type. If the value is `null` or `undefined`, returns `None`, otherwise
328
- * returns the value wrapped in a `Some`.
329
- *
330
- * @param nullableValue - The nullable value to be converted to an `Option`.
500
+ * Converts a nullable value into an `Option`. Returns `None` if the value is
501
+ * `null` or `undefined`, otherwise wraps the value in a `Some`.
331
502
  *
332
503
  * @example
333
504
  * ```ts
334
505
  * import { Option } from "effect"
335
506
  *
336
- * assert.deepStrictEqual(Option.fromNullable(undefined), Option.none())
337
- * assert.deepStrictEqual(Option.fromNullable(null), Option.none())
338
- * assert.deepStrictEqual(Option.fromNullable(1), Option.some(1))
507
+ * console.log(Option.fromNullable(undefined))
508
+ * // Output: { _id: 'Option', _tag: 'None' }
509
+ *
510
+ * console.log(Option.fromNullable(null))
511
+ * // Output: { _id: 'Option', _tag: 'None' }
512
+ *
513
+ * console.log(Option.fromNullable(1))
514
+ * // Output: { _id: 'Option', _tag: 'Some', value: 1 }
339
515
  * ```
340
516
  *
341
- * @category conversions
517
+ * @category Conversions
342
518
  * @since 2.0.0
343
519
  */
344
520
  exports.firstSomeOf = firstSomeOf;
345
521
  const fromNullable = nullableValue => nullableValue == null ? none() : some(nullableValue);
346
522
  /**
347
- * This API is useful for lifting a function that returns `null` or `undefined` into the `Option` context.
523
+ * Lifts a function that returns `null` or `undefined` into the `Option`
524
+ * context.
525
+ *
526
+ * **Details**
527
+ *
528
+ * This function takes a function `f` that might return `null` or `undefined`
529
+ * and transforms it into a function that returns an `Option`. The resulting
530
+ * function will return:
531
+ * - `Some` if the original function produces a non-null, non-undefined value.
532
+ * - `None` if the original function produces `null` or `undefined`.
348
533
  *
349
534
  * @example
350
535
  * ```ts
@@ -357,57 +542,86 @@ const fromNullable = nullableValue => nullableValue == null ? none() : some(null
357
542
  *
358
543
  * const parseOption = Option.liftNullable(parse)
359
544
  *
360
- * assert.deepStrictEqual(parseOption('1'), Option.some(1))
361
- * assert.deepStrictEqual(parseOption('not a number'), Option.none())
545
+ * console.log(parseOption("1"))
546
+ * // Output: { _id: 'Option', _tag: 'Some', value: 1 }
547
+ *
548
+ * console.log(parseOption("not a number"))
549
+ * // Output: { _id: 'Option', _tag: 'None' }
362
550
  * ```
363
551
  *
364
- * @category conversions
552
+ * @category Conversions
365
553
  * @since 2.0.0
366
554
  */
367
555
  exports.fromNullable = fromNullable;
368
556
  const liftNullable = f => (...a) => fromNullable(f(...a));
369
557
  /**
370
- * Returns the value of the `Option` if it is a `Some`, otherwise returns `null`.
558
+ * Returns the value contained in the `Option` if it is `Some`; otherwise,
559
+ * returns `null`.
560
+ *
561
+ * **Details**
562
+ *
563
+ * This function provides a way to extract the value of an `Option` while
564
+ * falling back to `null` if the `Option` is `None`.
371
565
  *
372
- * @param self - The `Option` to extract the value from.
566
+ * It is particularly useful in scenarios where `null` is an acceptable
567
+ * placeholder for the absence of a value, such as when interacting with APIs or
568
+ * systems that use `null` as a default for missing values.
373
569
  *
374
570
  * @example
375
571
  * ```ts
376
572
  * import { Option } from "effect"
377
573
  *
378
- * assert.deepStrictEqual(Option.getOrNull(Option.some(1)), 1)
379
- * assert.deepStrictEqual(Option.getOrNull(Option.none()), null)
574
+ * console.log(Option.getOrNull(Option.some(1)))
575
+ * // Output: 1
576
+ *
577
+ * console.log(Option.getOrNull(Option.none()))
578
+ * // Output: null
380
579
  * ```
381
580
  *
382
- * @category getters
581
+ * @category Getters
383
582
  * @since 2.0.0
384
583
  */
385
584
  exports.liftNullable = liftNullable;
386
585
  const getOrNull = exports.getOrNull = /*#__PURE__*/getOrElse(_Function.constNull);
387
586
  /**
388
- * Returns the value of the `Option` if it is a `Some`, otherwise returns `undefined`.
587
+ * Returns the value contained in the `Option` if it is `Some`; otherwise,
588
+ * returns `undefined`.
589
+ *
590
+ * **Details**
389
591
  *
390
- * @param self - The `Option` to extract the value from.
592
+ * This function provides a way to extract the value of an `Option` while
593
+ * falling back to `undefined` if the `Option` is `None`.
594
+ *
595
+ * It is particularly useful in scenarios where `undefined` is an acceptable
596
+ * placeholder for the absence of a value, such as when interacting with APIs or
597
+ * systems that use `undefined` as a default for missing values.
391
598
  *
392
599
  * @example
393
600
  * ```ts
394
601
  * import { Option } from "effect"
395
602
  *
396
- * assert.deepStrictEqual(Option.getOrUndefined(Option.some(1)), 1)
397
- * assert.deepStrictEqual(Option.getOrUndefined(Option.none()), undefined)
603
+ * console.log(Option.getOrUndefined(Option.some(1)))
604
+ * // Output: 1
605
+ *
606
+ * console.log(Option.getOrUndefined(Option.none()))
607
+ * // Output: undefined
398
608
  * ```
399
609
  *
400
- * @category getters
610
+ * @category Getters
401
611
  * @since 2.0.0
402
612
  */
403
613
  const getOrUndefined = exports.getOrUndefined = /*#__PURE__*/getOrElse(_Function.constUndefined);
404
614
  /**
405
- * A utility function that lifts a function that throws exceptions into a function that returns an `Option`.
615
+ * Lifts a function that throws exceptions into a function that returns an
616
+ * `Option`.
406
617
  *
407
- * This function is useful for any function that might throw an exception, allowing the developer to handle
408
- * the exception in a more functional way.
618
+ * **Details**
409
619
  *
410
- * @param f - the function that can throw exceptions.
620
+ * This utility function takes a function `f` that might throw an exception and
621
+ * transforms it into a safer function that returns an `Option`. If the original
622
+ * function executes successfully, the result is wrapped in a `Some`. If an
623
+ * exception is thrown, the result is `None`, allowing the developer to handle
624
+ * errors in a functional, type-safe way.
411
625
  *
412
626
  * @example
413
627
  * ```ts
@@ -415,11 +629,14 @@ const getOrUndefined = exports.getOrUndefined = /*#__PURE__*/getOrElse(_Function
415
629
  *
416
630
  * const parse = Option.liftThrowable(JSON.parse)
417
631
  *
418
- * assert.deepStrictEqual(parse("1"), Option.some(1))
419
- * assert.deepStrictEqual(parse(""), Option.none())
632
+ * console.log(parse("1"))
633
+ * // Output: { _id: 'Option', _tag: 'Some', value: 1 }
634
+ *
635
+ * console.log(parse(""))
636
+ * // Output: { _id: 'Option', _tag: 'None' }
420
637
  * ```
421
638
  *
422
- * @category conversions
639
+ * @category Conversions
423
640
  * @since 2.0.0
424
641
  */
425
642
  const liftThrowable = f => (...a) => {
@@ -430,12 +647,18 @@ const liftThrowable = f => (...a) => {
430
647
  }
431
648
  };
432
649
  /**
433
- * Extracts the value of an `Option` or throws if the `Option` is `None`.
650
+ * Extracts the value of an `Option` or throws an error if the `Option` is
651
+ * `None`, using a custom error factory.
652
+ *
653
+ * **Details**
434
654
  *
435
- * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.
655
+ * This function allows you to extract the value of an `Option` when it is
656
+ * `Some`. If the `Option` is `None`, it throws an error generated by the
657
+ * provided `onNone` function. This utility is particularly useful when you need
658
+ * a fail-fast behavior for empty `Option` values and want to provide a custom
659
+ * error message or object.
436
660
  *
437
- * @param self - The `Option` to extract the value from.
438
- * @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.
661
+ * @see {@link getOrThrow} for a version that throws a default error.
439
662
  *
440
663
  * @example
441
664
  * ```ts
@@ -448,7 +671,7 @@ const liftThrowable = f => (...a) => {
448
671
  * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))
449
672
  * ```
450
673
  *
451
- * @category conversions
674
+ * @category Conversions
452
675
  * @since 2.0.0
453
676
  */
454
677
  exports.liftThrowable = liftThrowable;
@@ -459,12 +682,17 @@ const getOrThrowWith = exports.getOrThrowWith = /*#__PURE__*/(0, _Function.dual)
459
682
  throw onNone();
460
683
  });
461
684
  /**
462
- * Extracts the value of an `Option` or throws if the `Option` is `None`.
685
+ * Extracts the value of an `Option` or throws a default error if the `Option`
686
+ * is `None`.
463
687
  *
464
- * The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.
688
+ * **Details**
465
689
  *
466
- * @param self - The `Option` to extract the value from.
467
- * @throws `Error("getOrThrow called on a None")`
690
+ * This function extracts the value from an `Option` if it is `Some`. If the
691
+ * `Option` is `None`, it throws a default error. It is useful for fail-fast
692
+ * scenarios where the absence of a value is treated as an exceptional case and
693
+ * a default error is sufficient.
694
+ *
695
+ * @see {@link getOrThrowWith} for a version that allows you to provide a custom error.
468
696
  *
469
697
  * @example
470
698
  * ```ts
@@ -474,48 +702,168 @@ const getOrThrowWith = exports.getOrThrowWith = /*#__PURE__*/(0, _Function.dual)
474
702
  * assert.throws(() => Option.getOrThrow(Option.none()))
475
703
  * ```
476
704
  *
477
- * @category conversions
705
+ * @category Conversions
478
706
  * @since 2.0.0
479
707
  */
480
708
  const getOrThrow = exports.getOrThrow = /*#__PURE__*/getOrThrowWith(() => new Error("getOrThrow called on a None"));
481
709
  /**
482
- * Maps the `Some` side of an `Option` value to a new `Option` value.
710
+ * Transforms the value inside a `Some` to a new value using the provided
711
+ * function, while leaving `None` unchanged.
712
+ *
713
+ * **Details**
714
+ *
715
+ * This function applies a mapping function `f` to the value inside an `Option`
716
+ * if it is a `Some`. If the `Option` is `None`, it remains unchanged. The
717
+ * result is a new `Option` with the transformed value (if it was a `Some`) or
718
+ * still `None`.
719
+ *
720
+ * This utility is particularly useful for chaining transformations in a
721
+ * functional way without needing to manually handle `None` cases.
722
+ *
723
+ * @example
724
+ * ```ts
725
+ * import { Option } from "effect"
483
726
  *
484
- * @param self - An `Option` to map
485
- * @param f - The function to map over the value of the `Option`
727
+ * // Mapping over a `Some`
728
+ * const someValue = Option.some(2)
486
729
  *
487
- * @category mapping
730
+ * console.log(Option.map(someValue, (n) => n * 2))
731
+ * // Output: { _id: 'Option', _tag: 'Some', value: 4 }
732
+ *
733
+ * // Mapping over a `None`
734
+ * const noneValue = Option.none<number>()
735
+ *
736
+ * console.log(Option.map(noneValue, (n) => n * 2))
737
+ * // Output: { _id: 'Option', _tag: 'None' }
738
+ * ```
739
+ *
740
+ * @category Mapping
488
741
  * @since 2.0.0
489
742
  */
490
743
  const map = exports.map = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => isNone(self) ? none() : some(f(self.value)));
491
744
  /**
492
- * Maps the `Some` value of this `Option` to the specified constant value.
745
+ * Replaces the value inside a `Some` with the specified constant value, leaving
746
+ * `None` unchanged.
747
+ *
748
+ * **Details**
493
749
  *
494
- * @category mapping
750
+ * This function transforms an `Option` by replacing the value inside a `Some`
751
+ * with the given constant value `b`. If the `Option` is `None`, it remains
752
+ * unchanged.
753
+ *
754
+ * This is useful when you want to preserve the presence of a value (`Some`) but
755
+ * replace its content with a fixed value.
756
+ *
757
+ * @example
758
+ * ```ts
759
+ * import { Option } from "effect"
760
+ *
761
+ * // Replacing the value of a `Some`
762
+ * const someValue = Option.some(42)
763
+ *
764
+ * console.log(Option.as(someValue, "new value"))
765
+ * // Output: { _id: 'Option', _tag: 'Some', value: 'new value' }
766
+ *
767
+ * // Replacing a `None` (no effect)
768
+ * const noneValue = Option.none<number>()
769
+ *
770
+ * console.log(Option.as(noneValue, "new value"))
771
+ * // Output: { _id: 'Option', _tag: 'None' }
772
+ * ```
773
+ *
774
+ * @category Mapping
495
775
  * @since 2.0.0
496
776
  */
497
777
  const as = exports.as = /*#__PURE__*/(0, _Function.dual)(2, (self, b) => map(self, () => b));
498
778
  /**
499
- * Maps the `Some` value of this `Option` to the `void` constant value.
779
+ * Replaces the value inside a `Some` with the constant value `void`, leaving
780
+ * `None` unchanged.
781
+ *
782
+ * **Details**
500
783
  *
501
- * This is useful when the value of the `Option` is not needed, but the presence or absence of the value is important.
784
+ * This function transforms an `Option` by replacing the value inside a `Some`
785
+ * with `void`. If the `Option` is `None`, it remains unchanged.
502
786
  *
503
- * @category mapping
787
+ * This is particularly useful in scenarios where the presence or absence of a
788
+ * value is significant, but the actual content of the value is irrelevant.
789
+ *
790
+ * @category Mapping
504
791
  * @since 2.0.0
505
792
  */
506
793
  const asVoid = exports.asVoid = /*#__PURE__*/as(undefined);
507
794
  const void_ = exports.void = /*#__PURE__*/some(undefined);
508
795
  /**
509
- * Applies a function to the value of an `Option` and flattens the result, if the input is `Some`.
796
+ * Applies a function to the value of a `Some` and flattens the resulting
797
+ * `Option`. If the input is `None`, it remains `None`.
798
+ *
799
+ * **Details**
800
+ *
801
+ * This function allows you to chain computations that return `Option` values.
802
+ * If the input `Option` is `Some`, the provided function `f` is applied to the
803
+ * contained value, and the resulting `Option` is returned. If the input is
804
+ * `None`, the function is not applied, and the result remains `None`.
805
+ *
806
+ * This utility is particularly useful for sequencing operations that may fail
807
+ * or produce optional results, enabling clean and concise workflows for
808
+ * handling such cases.
809
+ *
810
+ * @example
811
+ * ```ts
812
+ * import { Option } from "effect"
813
+ *
814
+ * interface Address {
815
+ * readonly city: string
816
+ * readonly street: Option.Option<string>
817
+ * }
818
+ *
819
+ * interface User {
820
+ * readonly id: number
821
+ * readonly username: string
822
+ * readonly email: Option.Option<string>
823
+ * readonly address: Option.Option<Address>
824
+ * }
825
+ *
826
+ * const user: User = {
827
+ * id: 1,
828
+ * username: "john_doe",
829
+ * email: Option.some("john.doe@example.com"),
830
+ * address: Option.some({
831
+ * city: "New York",
832
+ * street: Option.some("123 Main St")
833
+ * })
834
+ * }
835
+ *
836
+ * // Use flatMap to extract the street value
837
+ * const street = user.address.pipe(
838
+ * Option.flatMap((address) => address.street)
839
+ * )
840
+ *
841
+ * console.log(street)
842
+ * // Output: { _id: 'Option', _tag: 'Some', value: '123 Main St' }
843
+ * ```
510
844
  *
511
- * @category sequencing
845
+ * @category Sequencing
512
846
  * @since 2.0.0
513
847
  */
514
848
  const flatMap = exports.flatMap = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => isNone(self) ? none() : f(self.value));
515
849
  /**
516
- * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.
850
+ * Chains two `Option`s together. The second `Option` can either be a static
851
+ * value or depend on the result of the first `Option`.
852
+ *
853
+ * **Details**
854
+ *
855
+ * This function enables sequencing of two `Option` computations. If the first
856
+ * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can
857
+ * either:
858
+ *
859
+ * - Be a static `Option` value.
860
+ * - Be a function that produces an `Option`, optionally based on the value of
861
+ * the first `Option`.
862
+ *
863
+ * If the first `Option` is `None`, the function skips the evaluation of the
864
+ * second `Option` and directly returns `None`.
517
865
  *
518
- * @category sequencing
866
+ * @category Sequencing
519
867
  * @since 2.0.0
520
868
  */
521
869
  const andThen = exports.andThen = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => flatMap(self, a => {
@@ -523,11 +871,24 @@ const andThen = exports.andThen = /*#__PURE__*/(0, _Function.dual)(2, (self, f)
523
871
  return isOption(b) ? b : some(b);
524
872
  }));
525
873
  /**
526
- * This is `flatMap` + `fromNullable`, useful when working with optional values.
874
+ * Combines `flatMap` and `fromNullable`, transforming the value inside a `Some`
875
+ * using a function that may return `null` or `undefined`.
876
+ *
877
+ * **Details**
878
+ *
879
+ * This function applies a transformation function `f` to the value inside a
880
+ * `Some`. The function `f` may return a value, `null`, or `undefined`. If `f`
881
+ * returns a value, it is wrapped in a `Some`. If `f` returns `null` or
882
+ * `undefined`, the result is `None`. If the input `Option` is `None`, the
883
+ * function is not applied, and `None` is returned.
884
+ *
885
+ * This utility is particularly useful when working with deeply nested optional
886
+ * values or chaining computations that may result in `null` or `undefined` at
887
+ * some point.
527
888
  *
528
889
  * @example
529
890
  * ```ts
530
- * import { pipe, Option } from "effect"
891
+ * import { Option } from "effect"
531
892
  *
532
893
  * interface Employee {
533
894
  * company?: {
@@ -539,66 +900,133 @@ const andThen = exports.andThen = /*#__PURE__*/(0, _Function.dual)(2, (self, f)
539
900
  * }
540
901
  * }
541
902
  *
542
- * const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }
903
+ * const employee1: Employee = { company: { address: { street: { name: "high street" } } } }
543
904
  *
544
- * assert.deepStrictEqual(
545
- * pipe(
546
- * Option.some(employee1),
547
- * Option.flatMapNullable(employee => employee.company?.address?.street?.name),
548
- * ),
549
- * Option.some('high street')
905
+ * // Extracting a deeply nested property
906
+ * console.log(
907
+ * Option.some(employee1)
908
+ * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))
550
909
  * )
910
+ * // Output: { _id: 'Option', _tag: 'Some', value: 'high street' }
551
911
  *
552
912
  * const employee2: Employee = { company: { address: { street: {} } } }
553
913
  *
554
- * assert.deepStrictEqual(
555
- * pipe(
556
- * Option.some(employee2),
557
- * Option.flatMapNullable(employee => employee.company?.address?.street?.name),
558
- * ),
559
- * Option.none()
914
+ * // Property does not exist
915
+ * console.log(
916
+ * Option.some(employee2)
917
+ * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))
560
918
  * )
919
+ * // Output: { _id: 'Option', _tag: 'None' }
561
920
  * ```
562
921
  *
563
- * @category sequencing
922
+ * @category Sequencing
564
923
  * @since 2.0.0
565
924
  */
566
925
  const flatMapNullable = exports.flatMapNullable = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => isNone(self) ? none() : fromNullable(f(self.value)));
567
926
  /**
568
- * @category sequencing
927
+ * Flattens an `Option` of `Option` into a single `Option`.
928
+ *
929
+ * **Details**
930
+ *
931
+ * This function takes an `Option` that wraps another `Option` and flattens it
932
+ * into a single `Option`. If the outer `Option` is `Some`, the function
933
+ * extracts the inner `Option`. If the outer `Option` is `None`, the result
934
+ * remains `None`.
935
+ *
936
+ * This is useful for simplifying nested `Option` structures that may arise
937
+ * during functional operations.
938
+ *
939
+ * @category Sequencing
569
940
  * @since 2.0.0
570
941
  */
571
942
  const flatten = exports.flatten = /*#__PURE__*/flatMap(_Function.identity);
572
943
  /**
573
- * @category zipping
944
+ * Combines two `Option`s, keeping the value from the second `Option` if both
945
+ * are `Some`.
946
+ *
947
+ * **Details**
948
+ *
949
+ * This function takes two `Option`s and returns the second one if the first is
950
+ * `Some`. If the first `Option` is `None`, the result will also be `None`,
951
+ * regardless of the second `Option`. It effectively "zips" the two `Option`s
952
+ * while discarding the value from the first `Option`.
953
+ *
954
+ * This is particularly useful when sequencing computations where the result of
955
+ * the first computation is not needed, and you only care about the result of
956
+ * the second computation.
957
+ *
958
+ * @category Zipping
574
959
  * @since 2.0.0
575
960
  */
576
961
  const zipRight = exports.zipRight = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => flatMap(self, () => that));
577
962
  /**
578
- * @category sequencing
963
+ * Combines two `Option`s, keeping the value from the first `Option` if both are
964
+ * `Some`.
965
+ *
966
+ * **Details**
967
+ *
968
+ * This function takes two `Option`s and returns the first one if it is `Some`.
969
+ * If either the first `Option` or the second `Option` is `None`, the result
970
+ * will be `None`. This operation "zips" the two `Option`s while discarding the
971
+ * value from the second `Option`.
972
+ *
973
+ * This is useful when sequencing computations where the second `Option`
974
+ * represents a dependency or condition that must hold, but its value is
975
+ * irrelevant.
976
+ *
977
+ * @category Zipping
579
978
  * @since 2.0.0
580
979
  */
581
- const composeK = exports.composeK = /*#__PURE__*/(0, _Function.dual)(2, (afb, bfc) => a => flatMap(afb(a), bfc));
980
+ const zipLeft = exports.zipLeft = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => tap(self, () => that));
582
981
  /**
583
- * Sequences the specified `that` `Option` but ignores its value.
982
+ * Composes two functions that return `Option` values, creating a new function
983
+ * that chains them together.
584
984
  *
585
- * It is useful when we want to chain multiple operations, but only care about the result of `self`.
985
+ * **Details**
586
986
  *
587
- * @param that - The `Option` that will be ignored in the chain and discarded
588
- * @param self - The `Option` we care about
987
+ * This function allows you to compose two computations, each represented by a
988
+ * function that returns an `Option`. The result of the first function is passed
989
+ * to the second function if it is `Some`. If the first function returns `None`,
990
+ * the composed function short-circuits and returns `None` without invoking the
991
+ * second function.
992
+ *
993
+ * @example
994
+ * ```ts
995
+ * import { Option } from "effect"
996
+ *
997
+ * const parse = (s: string): Option.Option<number> => isNaN(Number(s)) ? Option.none() : Option.some(Number(s))
998
+ *
999
+ * const double = (n: number): Option.Option<number> => n > 0 ? Option.some(n * 2) : Option.none()
1000
+ *
1001
+ * const parseAndDouble = Option.composeK(parse, double)
1002
+ *
1003
+ * console.log(parseAndDouble("42"))
1004
+ * // Output: { _id: 'Option', _tag: 'Some', value: 84 }
1005
+ *
1006
+ * console.log(parseAndDouble("not a number"))
1007
+ * // Output: { _id: 'Option', _tag: 'None' }
1008
+ * ```
589
1009
  *
590
- * @category zipping
1010
+ * @category Sequencing
591
1011
  * @since 2.0.0
592
1012
  */
593
- const zipLeft = exports.zipLeft = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => tap(self, () => that));
1013
+ const composeK = exports.composeK = /*#__PURE__*/(0, _Function.dual)(2, (afb, bfc) => a => flatMap(afb(a), bfc));
594
1014
  /**
595
- * Applies the provided function `f` to the value of the `Option` if it is `Some` and returns the original `Option`
596
- * unless `f` returns `None`, in which case it returns `None`.
1015
+ * Applies the provided function `f` to the value of the `Option` if it is
1016
+ * `Some` and returns the original `Option`, unless `f` returns `None`, in which
1017
+ * case it returns `None`.
1018
+ *
1019
+ * **Details**
597
1020
  *
598
- * This function is useful for performing additional computations on the value of the input `Option` without affecting its value.
1021
+ * This function allows you to perform additional computations on the value of
1022
+ * an `Option` without modifying its original value. If the `Option` is `Some`,
1023
+ * the provided function `f` is executed with the value, and its result
1024
+ * determines whether the original `Option` is returned (`Some`) or the result
1025
+ * is `None` if `f` returns `None`. If the input `Option` is `None`, the
1026
+ * function is not executed, and `None` is returned.
599
1027
  *
600
- * @param f - Function to apply to the value of the `Option` if it is `Some`
601
- * @param self - The `Option` to apply the function to
1028
+ * This is particularly useful for applying side conditions or performing
1029
+ * validation checks while retaining the original `Option`'s value.
602
1030
  *
603
1031
  * @example
604
1032
  * ```ts
@@ -606,22 +1034,47 @@ const zipLeft = exports.zipLeft = /*#__PURE__*/(0, _Function.dual)(2, (self, tha
606
1034
  *
607
1035
  * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()
608
1036
  *
609
- * assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none())
610
- * assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1))
611
- * assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none())
1037
+ * console.log(Option.tap(Option.none(), getInteger))
1038
+ * // Output: { _id: 'Option', _tag: 'None' }
1039
+ *
1040
+ * console.log(Option.tap(Option.some(1), getInteger))
1041
+ * // Output: { _id: 'Option', _tag: 'Some', value: 1 }
1042
+ *
1043
+ * console.log(Option.tap(Option.some(1.14), getInteger))
1044
+ * // Output: { _id: 'Option', _tag: 'None' }
612
1045
  * ```
613
1046
  *
614
- * @category sequencing
1047
+ * @category Sequencing
615
1048
  * @since 2.0.0
616
1049
  */
617
1050
  const tap = exports.tap = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => flatMap(self, a => map(f(a), () => a)));
618
1051
  /**
619
- * @category combining
1052
+ * Combines two `Option` values into a single `Option` containing a tuple of
1053
+ * their values if both are `Some`.
1054
+ *
1055
+ * **Details**
1056
+ *
1057
+ * This function takes two `Option`s and combines their values into a tuple `[A,
1058
+ * B]` if both are `Some`. If either of the `Option`s is `None`, the result is
1059
+ * `None`. This is particularly useful for combining multiple `Option` values
1060
+ * into a single one, ensuring both contain valid values.
1061
+ *
1062
+ * @category Combining
620
1063
  * @since 2.0.0
621
1064
  */
622
1065
  const product = (self, that) => isSome(self) && isSome(that) ? some([self.value, that.value]) : none();
623
1066
  /**
624
- * @category combining
1067
+ * Combines an `Option` with a collection of `Option`s into a single `Option`
1068
+ * containing a tuple of their values if all are `Some`.
1069
+ *
1070
+ * **Details**
1071
+ *
1072
+ * This function takes a primary `Option` and a collection of `Option`s and
1073
+ * combines their values into a tuple `[A, ...Array<A>]` if all are `Some`. If
1074
+ * the primary `Option` or any `Option` in the collection is `None`, the result
1075
+ * is `None`.
1076
+ *
1077
+ * @category Combining
625
1078
  * @since 2.0.0
626
1079
  */
627
1080
  exports.product = product;
@@ -639,24 +1092,47 @@ const productMany = (self, collection) => {
639
1092
  return some(out);
640
1093
  };
641
1094
  /**
642
- * Takes a structure of `Option`s and returns an `Option` of values with the same structure.
1095
+ * Combines a structure of `Option`s into a single `Option` containing the
1096
+ * values with the same structure.
1097
+ *
1098
+ * **Details**
643
1099
  *
644
- * - If a tuple is supplied, then the returned `Option` will contain a tuple with the same length.
645
- * - If a struct is supplied, then the returned `Option` will contain a struct with the same keys.
646
- * - If an iterable is supplied, then the returned `Option` will contain an array.
1100
+ * This function takes a structure of `Option`s (a tuple, struct, or iterable)
1101
+ * and produces a single `Option` that contains the values from the input
1102
+ * structure if all `Option`s are `Some`. If any `Option` in the input is
1103
+ * `None`, the result is `None`. The structure of the input is preserved in the
1104
+ * output.
647
1105
  *
648
- * @param fields - the struct of `Option`s to be sequenced.
1106
+ * - If the input is a tuple (e.g., an array), the result will be an `Option`
1107
+ * containing a tuple with the same length.
1108
+ * - If the input is a struct (e.g., an object), the result will be an `Option`
1109
+ * containing a struct with the same keys.
1110
+ * - If the input is an iterable, the result will be an `Option` containing an
1111
+ * array.
649
1112
  *
650
1113
  * @example
651
1114
  * ```ts
652
1115
  * import { Option } from "effect"
653
1116
  *
654
- * assert.deepStrictEqual(Option.all([Option.some(1), Option.some(2)]), Option.some([1, 2]))
655
- * assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.some("hello") }), Option.some({ a: 1, b: "hello" }))
656
- * assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.none() }), Option.none())
1117
+ * const maybeName: Option.Option<string> = Option.some("John")
1118
+ * const maybeAge: Option.Option<number> = Option.some(25)
1119
+ *
1120
+ * // ┌─── Option<[string, number]>
1121
+ * // ▼
1122
+ * const tuple = Option.all([maybeName, maybeAge])
1123
+ * console.log(tuple)
1124
+ * // Output:
1125
+ * // { _id: 'Option', _tag: 'Some', value: [ 'John', 25 ] }
1126
+ *
1127
+ * // ┌─── Option<{ name: string; age: number; }>
1128
+ * // ▼
1129
+ * const struct = Option.all({ name: maybeName, age: maybeAge })
1130
+ * console.log(struct)
1131
+ * // Output:
1132
+ * // { _id: 'Option', _tag: 'Some', value: { name: 'John', age: 25 } }
657
1133
  * ```
658
1134
  *
659
- * @category combining
1135
+ * @category Combining
660
1136
  * @since 2.0.0
661
1137
  */
662
1138
  // @ts-expect-error
@@ -683,54 +1159,82 @@ const all = input => {
683
1159
  return some(out);
684
1160
  };
685
1161
  /**
686
- * Zips two `Option` values together using a provided function, returning a new `Option` of the result.
1162
+ * Combines two `Option` values into a new `Option` by applying a provided
1163
+ * function to their values.
1164
+ *
1165
+ * **Details**
1166
+ *
1167
+ * This function takes two `Option` values (`self` and `that`) and a combining
1168
+ * function `f`. If both `Option` values are `Some`, the function `f` is applied
1169
+ * to their values, and the result is wrapped in a new `Some`. If either
1170
+ * `Option` is `None`, the result is `None`.
687
1171
  *
688
- * @param self - The left-hand side of the zip operation
689
- * @param that - The right-hand side of the zip operation
690
- * @param f - The function used to combine the values of the two `Option`s
1172
+ * This utility is useful for combining two optional computations into a single
1173
+ * result while maintaining type safety and avoiding explicit checks for `None`.
691
1174
  *
692
1175
  * @example
693
1176
  * ```ts
694
1177
  * import { Option } from "effect"
695
1178
  *
696
- * type Complex = [real: number, imaginary: number]
1179
+ * const maybeName: Option.Option<string> = Option.some("John")
1180
+ * const maybeAge: Option.Option<number> = Option.some(25)
697
1181
  *
698
- * const complex = (real: number, imaginary: number): Complex => [real, imaginary]
1182
+ * // Combine the name and age into a person object
1183
+ * const person = Option.zipWith(maybeName, maybeAge, (name, age) => ({
1184
+ * name: name.toUpperCase(),
1185
+ * age
1186
+ * }))
699
1187
  *
700
- * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.none(), complex), Option.none())
701
- * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.none(), complex), Option.none())
702
- * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.some(1), complex), Option.none())
703
- * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.some(2), complex), Option.some([1, 2]))
704
- *
705
- * assert.deepStrictEqual(Option.zipWith(Option.some(1), complex)(Option.some(2)), Option.some([2, 1]))
1188
+ * console.log(person)
1189
+ * // Output:
1190
+ * // { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }
706
1191
  * ```
707
1192
  *
708
- * @category zipping
1193
+ * @category Zipping
709
1194
  * @since 2.0.0
710
1195
  */
711
1196
  exports.all = all;
712
1197
  const zipWith = exports.zipWith = /*#__PURE__*/(0, _Function.dual)(3, (self, that, f) => map(product(self, that), ([a, b]) => f(a, b)));
713
1198
  /**
714
- * @category combining
1199
+ * Applies a function inside a `Some` to a value inside another `Some`,
1200
+ * combining them into a new `Option`.
1201
+ *
1202
+ * **Details**
1203
+ *
1204
+ * This function allows you to apply a function wrapped in an `Option` (`self`)
1205
+ * to a value wrapped in another `Option` (`that`). If both `Option`s are
1206
+ * `Some`, the function is applied to the value, and the result is wrapped in a
1207
+ * new `Some`. If either `Option` is `None`, the result is `None`.
1208
+ *
1209
+ * @category Combining
715
1210
  * @since 2.0.0
716
1211
  */
717
1212
  const ap = exports.ap = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => zipWith(self, that, (f, a) => f(a)));
718
1213
  /**
719
- * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, elements that are `None` are ignored.
1214
+ * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, ignoring
1215
+ * elements that are `None`.
720
1216
  *
721
- * @param self - The Iterable of `Option<A>` to be reduced.
722
- * @param b - The initial value of the accumulator.
723
- * @param f - The reducing function that takes the current accumulator value and the unwrapped value of an `Option<A>`.
1217
+ * **Details**
1218
+ *
1219
+ * This function takes an initial value of type `B` and a reducing function `f`
1220
+ * that combines the accumulator with values of type `A`. It processes an
1221
+ * iterable of `Option<A>`, applying `f` only to the `Some` values while
1222
+ * ignoring the `None` values. The result is a single value of type `B`.
1223
+ *
1224
+ * This utility is particularly useful for aggregating values from an iterable
1225
+ * of `Option`s while skipping the absent (`None`) values.
724
1226
  *
725
1227
  * @example
726
1228
  * ```ts
727
- * import { pipe, Option } from "effect"
1229
+ * import { Option, pipe } from "effect"
728
1230
  *
729
1231
  * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]
730
- * assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3)
1232
+ *
1233
+ * console.log(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)))
1234
+ * // Output: 3
731
1235
  * ```
732
1236
  *
733
- * @category folding
1237
+ * @category Reducing
734
1238
  * @since 2.0.0
735
1239
  */
736
1240
  const reduceCompact = exports.reduceCompact = /*#__PURE__*/(0, _Function.dual)(3, (self, b, f) => {
@@ -743,26 +1247,45 @@ const reduceCompact = exports.reduceCompact = /*#__PURE__*/(0, _Function.dual)(3
743
1247
  return out;
744
1248
  });
745
1249
  /**
746
- * Transforms an `Option` into an `Array`.
1250
+ * Converts an `Option` into an `Array`.
747
1251
  * If the input is `None`, an empty array is returned.
748
- * If the input is `Some`, the value is wrapped in an array.
749
- *
750
- * @param self - The `Option` to convert to an array.
1252
+ * If the input is `Some`, its value is wrapped in a single-element array.
751
1253
  *
752
1254
  * @example
753
1255
  * ```ts
754
1256
  * import { Option } from "effect"
755
1257
  *
756
- * assert.deepStrictEqual(Option.toArray(Option.some(1)), [1])
757
- * assert.deepStrictEqual(Option.toArray(Option.none()), [])
1258
+ * console.log(Option.toArray(Option.some(1)))
1259
+ * // Output: [1]
1260
+ *
1261
+ * console.log(Option.toArray(Option.none()))
1262
+ * // Output: []
758
1263
  * ```
759
1264
  *
760
- * @category conversions
1265
+ * @category Conversions
761
1266
  * @since 2.0.0
762
1267
  */
763
1268
  const toArray = self => isNone(self) ? [] : [self.value];
764
1269
  /**
765
- * @category filtering
1270
+ * Splits an `Option` into two `Option`s based on the result of a mapping
1271
+ * function that produces an `Either`.
1272
+ *
1273
+ * **Details**
1274
+ *
1275
+ * This function takes an `Option` and a mapping function `f` that converts its
1276
+ * value into an `Either`. It returns a tuple of two `Option`s:
1277
+ *
1278
+ * - The first `Option` (`left`) contains the value from the `Left` side of the
1279
+ * `Either` if it exists, otherwise `None`.
1280
+ * - The second `Option` (`right`) contains the value from the `Right` side of
1281
+ * the `Either` if it exists, otherwise `None`.
1282
+ *
1283
+ * If the input `Option` is `None`, both returned `Option`s are `None`.
1284
+ *
1285
+ * This utility is useful for filtering and categorizing the contents of an
1286
+ * `Option` based on a bifurcating computation.
1287
+ *
1288
+ * @category Filtering
766
1289
  * @since 2.0.0
767
1290
  */
768
1291
  exports.toArray = toArray;
@@ -774,25 +1297,40 @@ const partitionMap = exports.partitionMap = /*#__PURE__*/(0, _Function.dual)(2,
774
1297
  return either.isLeft(e) ? [some(e.left), none()] : [none(), some(e.right)];
775
1298
  });
776
1299
  /**
777
- * Maps over the value of an `Option` and filters out `None`s.
1300
+ * Maps over the value of an `Option` with a function that may return `None`,
1301
+ * effectively filtering and transforming the value.
1302
+ *
1303
+ * **Details**
778
1304
  *
779
- * Useful when in addition to filtering you also want to change the type of the `Option`.
1305
+ * This function allows you to both transform the value of a `Some` and filter
1306
+ * it at the same time. The mapping function `f` can either return a new
1307
+ * `Option` (to transform the value) or return `None` to filter it out. If the
1308
+ * input `Option` is `None`, the function is not applied, and the result remains
1309
+ * `None`.
780
1310
  *
781
- * @param self - The `Option` to map over.
782
- * @param f - A function to apply to the value of the `Option`.
1311
+ * This utility is particularly useful when you want to apply a transformation
1312
+ * to the value of an `Option` while conditionally removing invalid or unwanted
1313
+ * results.
783
1314
  *
784
1315
  * @example
785
1316
  * ```ts
786
1317
  * import { Option } from "effect"
787
1318
  *
788
- * const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none()
1319
+ * // Transform and filter numbers
1320
+ * const transformEven = (n: Option.Option<number>): Option.Option<string> =>
1321
+ * Option.flatMap(n, (n) => (n % 2 === 0 ? Option.some(`Even: ${n}`) : Option.none()))
789
1322
  *
790
- * assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none())
791
- * assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none())
792
- * assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2))
1323
+ * console.log(transformEven(Option.none()))
1324
+ * // Output: { _id: 'Option', _tag: 'None' }
1325
+ *
1326
+ * console.log(transformEven(Option.some(1)))
1327
+ * // Output: { _id: 'Option', _tag: 'None' }
1328
+ *
1329
+ * console.log(transformEven(Option.some(2)))
1330
+ * // Output: { _id: 'Option', _tag: 'Some', value: 'Even: 2' }
793
1331
  * ```
794
1332
  *
795
- * @category filtering
1333
+ * @category Filtering
796
1334
  * @since 2.0.0
797
1335
  */
798
1336
  const filterMap = exports.filterMap = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => isNone(self) ? none() : f(self.value));
@@ -801,150 +1339,277 @@ const filterMap = exports.filterMap = /*#__PURE__*/(0, _Function.dual)(2, (self,
801
1339
  *
802
1340
  * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.
803
1341
  *
804
- * @param predicate - A predicate function to apply to the `Option` value.
805
- * @param fb - The `Option` to filter.
806
- *
807
1342
  * @example
808
1343
  * ```ts
809
1344
  * import { Option } from "effect"
810
1345
  *
811
- * // predicate
812
- * const isEven = (n: number) => n % 2 === 0
1346
+ * const removeEmptyString = (input: Option.Option<string>) =>
1347
+ * Option.filter(input, (value) => value !== "")
813
1348
  *
814
- * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())
815
- * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())
816
- * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))
1349
+ * console.log(removeEmptyString(Option.none()))
1350
+ * // Output: { _id: 'Option', _tag: 'None' }
817
1351
  *
818
- * // refinement
819
- * const isNumber = (v: unknown): v is number => typeof v === "number"
1352
+ * console.log(removeEmptyString(Option.some("")))
1353
+ * // Output: { _id: 'Option', _tag: 'None' }
820
1354
  *
821
- * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())
822
- * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())
823
- * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))
1355
+ * console.log(removeEmptyString(Option.some("a")))
1356
+ * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }
824
1357
  * ```
825
1358
  *
826
- * @category filtering
1359
+ * @category Filtering
827
1360
  * @since 2.0.0
828
1361
  */
829
1362
  const filter = exports.filter = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => filterMap(self, b => predicate(b) ? option.some(b) : option.none));
830
1363
  /**
1364
+ * Creates an `Equivalence` instance for comparing `Option` values, using a
1365
+ * provided `Equivalence` for the inner type.
1366
+ *
1367
+ * **Details**
1368
+ *
1369
+ * This function takes an `Equivalence` instance for a specific type `A` and
1370
+ * produces an `Equivalence` instance for `Option<A>`. The resulting
1371
+ * `Equivalence` determines whether two `Option` values are equivalent:
1372
+ *
1373
+ * - Two `None`s are considered equivalent.
1374
+ * - A `Some` and a `None` are not equivalent.
1375
+ * - Two `Some` values are equivalent if their inner values are equivalent
1376
+ * according to the provided `Equivalence`.
1377
+ *
831
1378
  * @example
832
1379
  * ```ts
833
- * import { Option, Number } from "effect"
1380
+ * // Title: Comparing Optional Numbers for Equivalence
1381
+ * import { Number, Option } from "effect"
834
1382
  *
835
1383
  * const isEquivalent = Option.getEquivalence(Number.Equivalence)
836
- * assert.deepStrictEqual(isEquivalent(Option.none(), Option.none()), true)
837
- * assert.deepStrictEqual(isEquivalent(Option.none(), Option.some(1)), false)
838
- * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.none()), false)
839
- * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(2)), false)
840
- * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(1)), true)
1384
+ *
1385
+ * console.log(isEquivalent(Option.none(), Option.none()))
1386
+ * // Output: true
1387
+ *
1388
+ * console.log(isEquivalent(Option.none(), Option.some(1)))
1389
+ * // Output: false
1390
+ *
1391
+ * console.log(isEquivalent(Option.some(1), Option.none()))
1392
+ * // Output: false
1393
+ *
1394
+ * console.log(isEquivalent(Option.some(1), Option.some(2)))
1395
+ * // Output: false
1396
+ *
1397
+ * console.log(isEquivalent(Option.some(1), Option.some(1)))
1398
+ * // Output: true
841
1399
  * ```
842
1400
  *
843
- * @category equivalence
1401
+ * @category Equivalence
844
1402
  * @since 2.0.0
845
1403
  */
846
1404
  const getEquivalence = isEquivalent => Equivalence.make((x, y) => isNone(x) ? isNone(y) : isNone(y) ? false : isEquivalent(x.value, y.value));
847
1405
  /**
848
- * The `Order` instance allows `Option` values to be compared with
849
- * `compare`, whenever there is an `Order` instance for
850
- * the type the `Option` contains.
1406
+ * Creates an `Order` instance for comparing `Option` values, using a provided
1407
+ * `Order` for the inner type.
851
1408
  *
852
- * `None` is considered to be less than any `Some` value.
1409
+ * **Details**
1410
+ *
1411
+ * This function produces an `Order` instance for `Option<A>`, allowing `Option`
1412
+ * values to be compared:
1413
+ *
1414
+ * - `None` is always considered less than any `Some` value.
1415
+ * - If both are `Some`, their inner values are compared using the provided
1416
+ * `Order` instance.
853
1417
  *
854
1418
  * @example
855
1419
  * ```ts
856
- * import { pipe, Option, Number } from "effect"
857
- *
858
- * const O = Option.getOrder(Number.Order)
859
- * assert.deepStrictEqual(O(Option.none(), Option.none()), 0)
860
- * assert.deepStrictEqual(O(Option.none(), Option.some(1)), -1)
861
- * assert.deepStrictEqual(O(Option.some(1), Option.none()), 1)
862
- * assert.deepStrictEqual(O(Option.some(1), Option.some(2)), -1)
863
- * assert.deepStrictEqual(O(Option.some(1), Option.some(1)), 0)
1420
+ * import { Number, Option } from "effect"
1421
+ *
1422
+ * const order = Option.getOrder(Number.Order)
1423
+ *
1424
+ * console.log(order(Option.none(), Option.none()))
1425
+ * // Output: 0
1426
+ *
1427
+ * console.log(order(Option.none(), Option.some(1)))
1428
+ * // Output: -1
1429
+ *
1430
+ * console.log(order(Option.some(1), Option.none()))
1431
+ * // Output: 1
1432
+ *
1433
+ * console.log(order(Option.some(1), Option.some(2)))
1434
+ * // Output: -1
1435
+ *
1436
+ * console.log(order(Option.some(1), Option.some(1)))
1437
+ * // Output: 0
864
1438
  * ```
865
1439
  *
866
- * @category sorting
1440
+ * @category Sorting
867
1441
  * @since 2.0.0
868
1442
  */
869
1443
  exports.getEquivalence = getEquivalence;
870
1444
  const getOrder = O => order.make((self, that) => isSome(self) ? isSome(that) ? O(self.value, that.value) : 1 : -1);
871
1445
  /**
872
- * Lifts a binary function into `Option`.
1446
+ * Lifts a binary function to work with `Option` values, allowing the function
1447
+ * to operate on two `Option`s.
1448
+ *
1449
+ * **Details**
873
1450
  *
874
- * @param f - The function to lift.
1451
+ * This function takes a binary function `f` and returns a new function that
1452
+ * applies `f` to the values of two `Option`s (`self` and `that`). If both
1453
+ * `Option`s are `Some`, the binary function `f` is applied to their values, and
1454
+ * the result is wrapped in a new `Some`. If either `Option` is `None`, the
1455
+ * result is `None`.
875
1456
  *
876
- * @category lifting
1457
+ * @example
1458
+ * ```ts
1459
+ * import { Option } from "effect"
1460
+ *
1461
+ * // A binary function to add two numbers
1462
+ * const add = (a: number, b: number): number => a + b
1463
+ *
1464
+ * // Lift the `add` function to work with `Option` values
1465
+ * const addOptions = Option.lift2(add)
1466
+ *
1467
+ * // Both `Option`s are `Some`
1468
+ * console.log(addOptions(Option.some(2), Option.some(3)))
1469
+ * // Output: { _id: 'Option', _tag: 'Some', value: 5 }
1470
+ *
1471
+ * // One `Option` is `None`
1472
+ * console.log(addOptions(Option.some(2), Option.none()))
1473
+ * // Output: { _id: 'Option', _tag: 'None' }
1474
+ * ```
1475
+ *
1476
+ * @category Lifting
877
1477
  * @since 2.0.0
878
1478
  */
879
1479
  exports.getOrder = getOrder;
880
1480
  const lift2 = f => (0, _Function.dual)(2, (self, that) => zipWith(self, that, f));
881
1481
  /**
882
- * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`
883
- * if the predicate returns `false`.
1482
+ * Lifts a `Predicate` or `Refinement` into the `Option` context, returning a
1483
+ * `Some` of the input value if the predicate is satisfied, or `None` otherwise.
884
1484
  *
885
- * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.
1485
+ * **Details**
1486
+ *
1487
+ * This function transforms a `Predicate` (or a more specific `Refinement`) into
1488
+ * a function that produces an `Option`. If the predicate evaluates to `true`,
1489
+ * the input value is wrapped in a `Some`. If the predicate evaluates to
1490
+ * `false`, the result is `None`.
886
1491
  *
887
1492
  * @example
888
1493
  * ```ts
889
1494
  * import { Option } from "effect"
890
1495
  *
891
- * const getOption = Option.liftPredicate((n: number) => n >= 0)
1496
+ * // Check if a number is positive
1497
+ * const isPositive = (n: number) => n > 0
1498
+ *
1499
+ * // ┌─── (b: number) => Option<number>
1500
+ * // ▼
1501
+ * const parsePositive = Option.liftPredicate(isPositive)
892
1502
  *
893
- * assert.deepStrictEqual(getOption(-1), Option.none())
894
- * assert.deepStrictEqual(getOption(1), Option.some(1))
1503
+ * console.log(parsePositive(1))
1504
+ * // Output: { _id: 'Option', _tag: 'Some', value: 1 }
1505
+ *
1506
+ * console.log(parsePositive(-1))
1507
+ * // OUtput: { _id: 'Option', _tag: 'None' }
895
1508
  * ```
896
1509
  *
897
- * @category lifting
1510
+ * @category Lifting
898
1511
  * @since 2.0.0
899
1512
  */
900
1513
  exports.lift2 = lift2;
901
1514
  const liftPredicate = exports.liftPredicate = /*#__PURE__*/(0, _Function.dual)(2, (b, predicate) => predicate(b) ? some(b) : none());
902
1515
  /**
903
- * Returns a function that checks if a `Option` contains a given value using a provided `isEquivalent` function.
1516
+ * Returns a function that checks if an `Option` contains a specified value,
1517
+ * using a provided equivalence function.
1518
+ *
1519
+ * **Details**
904
1520
  *
905
- * @param equivalent - An `Equivalence` instance to compare values of the `Option`.
906
- * @param self - The `Option` to apply the comparison to.
907
- * @param a - The value to compare against the `Option`.
1521
+ * This function allows you to check whether an `Option` contains a specific
1522
+ * value. It uses an equivalence function `isEquivalent` to compare the value
1523
+ * inside the `Option` to the provided value. If the `Option` is `Some` and the
1524
+ * equivalence function returns `true`, the result is `true`. If the `Option` is
1525
+ * `None` or the values are not equivalent, the result is `false`.
1526
+ *
1527
+ * @see {@link contains} for a version that uses the default `Equivalence`.
908
1528
  *
909
1529
  * @example
910
1530
  * ```ts
911
- * import { pipe, Option, Number } from "effect"
1531
+ * import { Number, Option } from "effect"
1532
+ *
1533
+ * const contains = Option.containsWith(Number.Equivalence)
1534
+ *
1535
+ * console.log(Option.some(2).pipe(contains(2)))
1536
+ * // Output: true
1537
+ *
1538
+ * console.log(Option.some(1).pipe(contains(2)))
1539
+ * // Output: false
912
1540
  *
913
- * assert.deepStrictEqual(pipe(Option.some(2), Option.containsWith(Number.Equivalence)(2)), true)
914
- * assert.deepStrictEqual(pipe(Option.some(1), Option.containsWith(Number.Equivalence)(2)), false)
915
- * assert.deepStrictEqual(pipe(Option.none(), Option.containsWith(Number.Equivalence)(2)), false)
1541
+ * console.log(Option.none().pipe(contains(2)))
1542
+ * // Output: false
916
1543
  * ```
917
1544
  *
918
- * @category elements
1545
+ * @category Elements
919
1546
  * @since 2.0.0
920
1547
  */
921
1548
  const containsWith = isEquivalent => (0, _Function.dual)(2, (self, a) => isNone(self) ? false : isEquivalent(self.value, a));
922
1549
  exports.containsWith = containsWith;
923
1550
  const _equivalence = /*#__PURE__*/Equal.equivalence();
924
1551
  /**
925
- * Returns a function that checks if an `Option` contains a given value using the default `Equivalence`.
1552
+ * Returns a function that checks if an `Option` contains a specified value
1553
+ * using the default `Equivalence`.
926
1554
  *
927
- * @category elements
1555
+ * **Details**
1556
+ *
1557
+ * This function allows you to check whether an `Option` contains a specific
1558
+ * value. It uses the default `Equivalence` for equality comparison. If the
1559
+ * `Option` is `Some` and its value is equivalent to the provided value, the
1560
+ * result is `true`. If the `Option` is `None` or the values are not equivalent,
1561
+ * the result is `false`.
1562
+ *
1563
+ * @see {@link containsWith} for a version that allows you to specify a custom equivalence function.
1564
+ *
1565
+ * @example
1566
+ * ```ts
1567
+ * import { Option } from "effect"
1568
+ *
1569
+ * console.log(Option.some(2).pipe(Option.contains(2)))
1570
+ * // Output: true
1571
+ *
1572
+ * console.log(Option.some(1).pipe(Option.contains(2)))
1573
+ * // Output: false
1574
+ *
1575
+ * console.log(Option.none().pipe(Option.contains(2)))
1576
+ * // Output: false
1577
+ * ```
1578
+ *
1579
+ * @category Elements
928
1580
  * @since 2.0.0
929
1581
  */
930
1582
  const contains = exports.contains = /*#__PURE__*/containsWith(_equivalence);
931
1583
  /**
932
- * Check if a value in an `Option` type meets a certain predicate.
1584
+ * Checks if a value in an `Option` satisfies a given predicate or refinement.
1585
+ *
1586
+ * **Details**
1587
+ *
1588
+ * This function allows you to check if a value inside a `Some` meets a
1589
+ * specified condition. If the `Option` is `None`, the result is `false`. If the
1590
+ * `Option` is `Some`, the provided predicate or refinement is applied to the
1591
+ * value:
933
1592
  *
934
- * @param self - The `Option` to check.
935
- * @param predicate - The condition to check.
1593
+ * - If the condition is met, the result is `true`.
1594
+ * - If the condition is not met, the result is `false`.
936
1595
  *
937
1596
  * @example
938
1597
  * ```ts
939
- * import { pipe, Option } from "effect"
1598
+ * import { Option } from "effect"
940
1599
  *
941
1600
  * const isEven = (n: number) => n % 2 === 0
942
1601
  *
943
- * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)
944
- * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)
945
- * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)
1602
+ * console.log(Option.some(2).pipe(Option.exists(isEven)))
1603
+ * // Output: true
1604
+ *
1605
+ * console.log(Option.some(1).pipe(Option.exists(isEven)))
1606
+ * // Output: false
1607
+ *
1608
+ * console.log(Option.none().pipe(Option.exists(isEven)))
1609
+ * // Output: false
946
1610
  * ```
947
1611
  *
1612
+ * @category Elements
948
1613
  * @since 2.0.0
949
1614
  */
950
1615
  const exists = exports.exists = /*#__PURE__*/(0, _Function.dual)(2, (self, refinement) => isNone(self) ? false : refinement(self.value));
@@ -980,7 +1645,7 @@ const exists = exports.exists = /*#__PURE__*/(0, _Function.dual)(2, (self, refin
980
1645
  * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))
981
1646
  * ```
982
1647
  *
983
- * @category do notation
1648
+ * @category Do notation
984
1649
  * @since 2.0.0
985
1650
  */
986
1651
  const bindTo = exports.bindTo = /*#__PURE__*/doNotation.bindTo(map);
@@ -1014,7 +1679,7 @@ const let_ = exports.let = /*#__PURE__*/doNotation.let_(map);
1014
1679
  * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))
1015
1680
  * ```
1016
1681
  *
1017
- * @category do notation
1682
+ * @category Do notation
1018
1683
  * @since 2.0.0
1019
1684
  */
1020
1685
  const bind = exports.bind = /*#__PURE__*/doNotation.bind(map, flatMap);
@@ -1047,52 +1712,66 @@ const bind = exports.bind = /*#__PURE__*/doNotation.bind(map, flatMap);
1047
1712
  * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))
1048
1713
  * ```
1049
1714
  *
1050
- * @category do notation
1715
+ * @category Do notation
1051
1716
  * @since 2.0.0
1052
1717
  */
1053
1718
  const Do = exports.Do = /*#__PURE__*/some({});
1054
1719
  const adapter = /*#__PURE__*/Gen.adapter();
1055
1720
  /**
1056
- * @category generators
1721
+ * Similar to `Effect.gen`, `Option.gen` provides a more readable,
1722
+ * generator-based syntax for working with `Option` values, making code that
1723
+ * involves `Option` easier to write and understand. This approach is similar to
1724
+ * using `async/await` but tailored for `Option`.
1725
+ *
1726
+ * @example
1727
+ * ```ts
1728
+ * // Title: Using Option.gen to Create a Combined Value
1729
+ * import { Option } from "effect"
1730
+ *
1731
+ * const maybeName: Option.Option<string> = Option.some("John")
1732
+ * const maybeAge: Option.Option<number> = Option.some(25)
1733
+ *
1734
+ * const person = Option.gen(function* () {
1735
+ * const name = (yield* maybeName).toUpperCase()
1736
+ * const age = yield* maybeAge
1737
+ * return { name, age }
1738
+ * })
1739
+ *
1740
+ * console.log(person)
1741
+ * // Output:
1742
+ * // { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }
1743
+ * ```
1744
+ *
1745
+ * @category Generators
1057
1746
  * @since 2.0.0
1058
1747
  */
1059
1748
  const gen = (...args) => {
1060
- let f;
1061
- if (args.length === 1) {
1062
- f = args[0];
1063
- } else {
1064
- f = args[1].bind(args[0]);
1065
- }
1749
+ const f = args.length === 1 ? args[0] : args[1].bind(args[0]);
1066
1750
  const iterator = f(adapter);
1067
1751
  let state = iterator.next();
1068
- if (state.done) {
1069
- return some(state.value);
1070
- } else {
1071
- let current = state.value;
1072
- if (Gen.isGenKind(current)) {
1073
- current = current.value;
1074
- } else {
1075
- current = Gen.yieldWrapGet(current);
1076
- }
1752
+ while (!state.done) {
1753
+ const current = Gen.isGenKind(state.value) ? state.value.value : Gen.yieldWrapGet(state.value);
1077
1754
  if (isNone(current)) {
1078
1755
  return current;
1079
1756
  }
1080
- while (!state.done) {
1081
- state = iterator.next(current.value);
1082
- if (!state.done) {
1083
- current = state.value;
1084
- if (Gen.isGenKind(current)) {
1085
- current = current.value;
1086
- } else {
1087
- current = Gen.yieldWrapGet(current);
1088
- }
1089
- if (isNone(current)) {
1090
- return current;
1091
- }
1092
- }
1093
- }
1094
- return some(state.value);
1757
+ state = iterator.next(current.value);
1095
1758
  }
1759
+ return some(state.value);
1096
1760
  };
1761
+ /**
1762
+ * Merges two optional values, applying a function if both exist.
1763
+ * Unlike {@link zipWith}, this function returns `None` only if both inputs are `None`.
1764
+ *
1765
+ * @internal
1766
+ */
1097
1767
  exports.gen = gen;
1768
+ const mergeWith = f => (o1, o2) => {
1769
+ if (isNone(o1)) {
1770
+ return o2;
1771
+ } else if (isNone(o2)) {
1772
+ return o1;
1773
+ }
1774
+ return some(f(o1.value, o2.value));
1775
+ };
1776
+ exports.mergeWith = mergeWith;
1098
1777
  //# sourceMappingURL=Option.js.map