effect 4.0.0-beta.83 → 4.0.0-beta.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Array.d.ts +64 -64
- package/dist/Array.js +26 -26
- package/dist/Cache.d.ts +1 -1
- package/dist/Cache.js +1 -1
- package/dist/Cause.d.ts +68 -68
- package/dist/Cause.js +47 -47
- package/dist/Channel.d.ts +5 -5
- package/dist/Channel.js +3 -3
- package/dist/Clock.d.ts +1 -1
- package/dist/Clock.js +1 -1
- package/dist/Combiner.d.ts +9 -9
- package/dist/Combiner.js +8 -8
- package/dist/Config.d.ts +15 -94
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +22 -70
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.d.ts +58 -74
- package/dist/ConfigProvider.d.ts.map +1 -1
- package/dist/ConfigProvider.js +66 -41
- package/dist/ConfigProvider.js.map +1 -1
- package/dist/Console.d.ts +1 -1
- package/dist/Console.js +1 -1
- package/dist/Data.d.ts +15 -15
- package/dist/Data.js +3 -3
- package/dist/DateTime.d.ts +6 -6
- package/dist/DateTime.js +2 -2
- package/dist/Duration.d.ts +3 -3
- package/dist/Duration.js +3 -3
- package/dist/Effect.d.ts +84 -45
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +72 -33
- package/dist/Effect.js.map +1 -1
- package/dist/Equal.d.ts +7 -7
- package/dist/Equal.js +5 -5
- package/dist/Equivalence.d.ts +17 -17
- package/dist/Equivalence.js +13 -13
- package/dist/Exit.d.ts +3 -3
- package/dist/Exit.js +3 -3
- package/dist/Formatter.d.ts +5 -5
- package/dist/Formatter.js +4 -4
- package/dist/Function.d.ts +10 -10
- package/dist/Function.js +3 -3
- package/dist/HashMap.d.ts +3 -3
- package/dist/HashMap.js +1 -1
- package/dist/Iterable.d.ts +6 -6
- package/dist/Iterable.js +2 -2
- package/dist/JsonPatch.d.ts +2 -2
- package/dist/Layer.d.ts +1 -1
- package/dist/Layer.js +1 -1
- package/dist/Logger.d.ts +1 -1
- package/dist/Logger.js +1 -1
- package/dist/Match.d.ts +8 -8
- package/dist/Match.js +8 -8
- package/dist/Metric.d.ts +3 -3
- package/dist/Metric.js +3 -3
- package/dist/Optic.d.ts +30 -30
- package/dist/Optic.js +12 -12
- package/dist/Option.d.ts +7 -7
- package/dist/Option.js +7 -7
- package/dist/Order.d.ts +23 -23
- package/dist/Order.js +20 -20
- package/dist/Pool.d.ts +1 -1
- package/dist/Pool.js +1 -1
- package/dist/Predicate.d.ts +88 -88
- package/dist/Predicate.js +47 -47
- package/dist/PubSub.d.ts +3 -3
- package/dist/PubSub.js +3 -3
- package/dist/Reducer.d.ts +1 -1
- package/dist/Reducer.js +1 -1
- package/dist/Result.d.ts +18 -18
- package/dist/Result.js +8 -8
- package/dist/Runtime.d.ts +1 -1
- package/dist/Runtime.js +1 -1
- package/dist/Schema.d.ts +265 -120
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +285 -116
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +13 -9
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaGetter.d.ts +48 -48
- package/dist/SchemaGetter.js +44 -44
- package/dist/SchemaIssue.d.ts +3 -3
- package/dist/SchemaIssue.js +3 -3
- package/dist/SchemaParser.d.ts +122 -22
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +186 -50
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +1 -1
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +96 -2
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +20 -20
- package/dist/SchemaTransformation.js +18 -18
- package/dist/Stream.d.ts +3 -3
- package/dist/Stream.js +2 -2
- package/dist/Stream.js.map +1 -1
- package/dist/String.d.ts +1 -1
- package/dist/String.js +1 -1
- package/dist/Struct.d.ts +1 -1
- package/dist/Struct.js +1 -1
- package/dist/Types.d.ts +13 -13
- package/dist/internal/effect.js +23 -10
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/cause.d.ts +2 -0
- package/dist/internal/schema/cause.d.ts.map +1 -0
- package/dist/internal/schema/cause.js +24 -0
- package/dist/internal/schema/cause.js.map +1 -0
- package/dist/internal/schema/schema.d.ts +8 -4
- package/dist/internal/schema/schema.d.ts.map +1 -1
- package/dist/internal/schema/schema.js +21 -8
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +3 -3
- package/dist/testing/TestSchema.js +1 -1
- package/dist/unstable/ai/AiError.d.ts +1 -1
- package/dist/unstable/ai/AiError.js +1 -1
- package/dist/unstable/ai/Chat.d.ts +1 -1
- package/dist/unstable/ai/Chat.js +1 -1
- package/dist/unstable/cli/Prompt.js +2 -2
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
- package/dist/unstable/rpc/Rpc.d.ts +1 -1
- package/dist/unstable/rpc/Rpc.js +1 -1
- package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcGroup.js +3 -4
- package/dist/unstable/rpc/RpcGroup.js.map +1 -1
- package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
- package/dist/unstable/sql/SqlResolver.js +15 -2
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/workflow/Activity.d.ts +1 -0
- package/dist/unstable/workflow/Activity.d.ts.map +1 -1
- package/dist/unstable/workflow/Activity.js +1 -0
- package/dist/unstable/workflow/Activity.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +65 -65
- package/src/Cache.ts +1 -1
- package/src/Cause.ts +68 -68
- package/src/Channel.ts +5 -5
- package/src/Clock.ts +1 -1
- package/src/Combiner.ts +9 -9
- package/src/Config.ts +40 -108
- package/src/ConfigProvider.ts +139 -100
- package/src/Console.ts +1 -1
- package/src/Data.ts +15 -15
- package/src/DateTime.ts +6 -6
- package/src/Duration.ts +3 -3
- package/src/Effect.ts +89 -45
- package/src/Equal.ts +7 -7
- package/src/Equivalence.ts +17 -17
- package/src/Exit.ts +3 -3
- package/src/Formatter.ts +5 -5
- package/src/Function.ts +10 -10
- package/src/HashMap.ts +3 -3
- package/src/Iterable.ts +6 -6
- package/src/JsonPatch.ts +2 -2
- package/src/Layer.ts +1 -1
- package/src/Logger.ts +1 -1
- package/src/Match.ts +8 -8
- package/src/Metric.ts +3 -3
- package/src/Optic.ts +30 -30
- package/src/Option.ts +7 -7
- package/src/Order.ts +23 -23
- package/src/Pool.ts +1 -1
- package/src/Predicate.ts +88 -88
- package/src/PubSub.ts +3 -3
- package/src/Reducer.ts +1 -1
- package/src/Result.ts +20 -20
- package/src/Runtime.ts +1 -1
- package/src/Schema.ts +314 -131
- package/src/SchemaAST.ts +20 -11
- package/src/SchemaGetter.ts +48 -48
- package/src/SchemaIssue.ts +3 -3
- package/src/SchemaParser.ts +197 -58
- package/src/SchemaRepresentation.ts +73 -3
- package/src/SchemaTransformation.ts +20 -20
- package/src/Stream.ts +4 -4
- package/src/String.ts +1 -1
- package/src/Struct.ts +1 -1
- package/src/Types.ts +13 -13
- package/src/internal/effect.ts +29 -10
- package/src/internal/schema/cause.ts +26 -0
- package/src/internal/schema/schema.ts +36 -10
- package/src/testing/TestSchema.ts +3 -3
- package/src/unstable/ai/AiError.ts +1 -1
- package/src/unstable/ai/Chat.ts +1 -1
- package/src/unstable/cli/Prompt.ts +1 -1
- package/src/unstable/httpapi/HttpApiScalar.ts +2 -2
- package/src/unstable/rpc/Rpc.ts +1 -1
- package/src/unstable/rpc/RpcGroup.ts +3 -4
- package/src/unstable/sql/SqlResolver.ts +15 -2
- package/src/unstable/workflow/Activity.ts +2 -0
- package/src/unstable/workflow/WorkflowEngine.ts +1 -1
package/src/Iterable.ts
CHANGED
|
@@ -3233,7 +3233,7 @@ export const map: {
|
|
|
3233
3233
|
/**
|
|
3234
3234
|
* Applies a function to each element in an Iterable and returns a new Iterable containing the concatenated mapped elements.
|
|
3235
3235
|
*
|
|
3236
|
-
* **Example** (
|
|
3236
|
+
* **Example** (Flat mapping iterables)
|
|
3237
3237
|
*
|
|
3238
3238
|
* ```ts
|
|
3239
3239
|
* import { Iterable } from "effect"
|
|
@@ -3272,7 +3272,7 @@ export const flatMap: {
|
|
|
3272
3272
|
/**
|
|
3273
3273
|
* Applies a function to each element in an Iterable and returns a new Iterable containing the concatenated mapped elements.
|
|
3274
3274
|
*
|
|
3275
|
-
* **Example** (
|
|
3275
|
+
* **Example** (Flat mapping iterables)
|
|
3276
3276
|
*
|
|
3277
3277
|
* ```ts
|
|
3278
3278
|
* import { Iterable } from "effect"
|
|
@@ -3311,7 +3311,7 @@ export const flatMap: {
|
|
|
3311
3311
|
/**
|
|
3312
3312
|
* Applies a function to each element in an Iterable and returns a new Iterable containing the concatenated mapped elements.
|
|
3313
3313
|
*
|
|
3314
|
-
* **Example** (
|
|
3314
|
+
* **Example** (Flat mapping iterables)
|
|
3315
3315
|
*
|
|
3316
3316
|
* ```ts
|
|
3317
3317
|
* import { Iterable } from "effect"
|
|
@@ -4089,7 +4089,7 @@ export const filter: {
|
|
|
4089
4089
|
* Use when working with APIs or functions that return nullable values,
|
|
4090
4090
|
* providing a clean way to filter out null or undefined while transforming.
|
|
4091
4091
|
*
|
|
4092
|
-
* **Example** (
|
|
4092
|
+
* **Example** (Flat mapping nullable results)
|
|
4093
4093
|
*
|
|
4094
4094
|
* ```ts
|
|
4095
4095
|
* import { Iterable } from "effect"
|
|
@@ -4135,7 +4135,7 @@ export const flatMapNullishOr: {
|
|
|
4135
4135
|
* Use when working with APIs or functions that return nullable values,
|
|
4136
4136
|
* providing a clean way to filter out null or undefined while transforming.
|
|
4137
4137
|
*
|
|
4138
|
-
* **Example** (
|
|
4138
|
+
* **Example** (Flat mapping nullable results)
|
|
4139
4139
|
*
|
|
4140
4140
|
* ```ts
|
|
4141
4141
|
* import { Iterable } from "effect"
|
|
@@ -4181,7 +4181,7 @@ export const flatMapNullishOr: {
|
|
|
4181
4181
|
* Use when working with APIs or functions that return nullable values,
|
|
4182
4182
|
* providing a clean way to filter out null or undefined while transforming.
|
|
4183
4183
|
*
|
|
4184
|
-
* **Example** (
|
|
4184
|
+
* **Example** (Flat mapping nullable results)
|
|
4185
4185
|
*
|
|
4186
4186
|
* ```ts
|
|
4187
4187
|
* import { Iterable } from "effect"
|
package/src/JsonPatch.ts
CHANGED
|
@@ -29,7 +29,7 @@ import type * as Schema from "./Schema.ts"
|
|
|
29
29
|
* discriminated by the `op` field, and the optional `description` field can be
|
|
30
30
|
* used for documentation.
|
|
31
31
|
*
|
|
32
|
-
* **Example** (
|
|
32
|
+
* **Example** (Defining all operation types)
|
|
33
33
|
*
|
|
34
34
|
* ```ts
|
|
35
35
|
* import { JsonPatch } from "effect"
|
|
@@ -113,7 +113,7 @@ export type JsonPatchOperation =
|
|
|
113
113
|
* operations observe the document state produced by earlier operations. An empty
|
|
114
114
|
* array represents a no-op patch and returns the original document.
|
|
115
115
|
*
|
|
116
|
-
* **Example** (
|
|
116
|
+
* **Example** (Defining a multi-operation patch)
|
|
117
117
|
*
|
|
118
118
|
* ```ts
|
|
119
119
|
* import { JsonPatch } from "effect"
|
package/src/Layer.ts
CHANGED
|
@@ -4259,7 +4259,7 @@ export const span = (
|
|
|
4259
4259
|
* that are built with this layer. This API does not create, end, or close the
|
|
4260
4260
|
* span; the caller remains responsible for the span's lifetime.
|
|
4261
4261
|
*
|
|
4262
|
-
* **Example** (
|
|
4262
|
+
* **Example** (Referencing an existing parent span)
|
|
4263
4263
|
*
|
|
4264
4264
|
* ```ts
|
|
4265
4265
|
* import { Console, Context, Effect, Layer, Tracer } from "effect"
|
package/src/Logger.ts
CHANGED
|
@@ -547,7 +547,7 @@ export const make: <Message, Output>(
|
|
|
547
547
|
/**
|
|
548
548
|
* The default logging implementation used by the Effect runtime.
|
|
549
549
|
*
|
|
550
|
-
* **Example** (
|
|
550
|
+
* **Example** (Referencing the default logger)
|
|
551
551
|
*
|
|
552
552
|
* ```ts
|
|
553
553
|
* import { Effect, Logger } from "effect"
|
package/src/Match.ts
CHANGED
|
@@ -601,7 +601,7 @@ export const typeTags: {
|
|
|
601
601
|
* **Important:** This function must be the first step in the matcher pipeline.
|
|
602
602
|
* If used later, TypeScript will not enforce type consistency correctly.
|
|
603
603
|
*
|
|
604
|
-
* **Example** (Validating
|
|
604
|
+
* **Example** (Validating return type consistency)
|
|
605
605
|
*
|
|
606
606
|
* ```ts
|
|
607
607
|
* import { Match } from "effect"
|
|
@@ -641,7 +641,7 @@ export const withReturnType: <Ret>() => <I, F, R, A, Pr, _>(
|
|
|
641
641
|
* pattern matches, the associated function is executed and the matched input is
|
|
642
642
|
* removed from the remaining cases tracked by the matcher.
|
|
643
643
|
*
|
|
644
|
-
* **Example** (Matching with
|
|
644
|
+
* **Example** (Matching with values and predicates)
|
|
645
645
|
*
|
|
646
646
|
* ```ts
|
|
647
647
|
* import { Match } from "effect"
|
|
@@ -1055,7 +1055,7 @@ export const discriminatorsExhaustive: <D extends string>(
|
|
|
1055
1055
|
* `"_tag"` as their discriminator field. Use {@link discriminator} for a
|
|
1056
1056
|
* different discriminator field.
|
|
1057
1057
|
*
|
|
1058
|
-
* **Example** (Matching a
|
|
1058
|
+
* **Example** (Matching a discriminated union by tag)
|
|
1059
1059
|
*
|
|
1060
1060
|
* ```ts
|
|
1061
1061
|
* import { Match } from "effect"
|
|
@@ -1268,7 +1268,7 @@ export const tagsExhaustive: <
|
|
|
1268
1268
|
* Any excluded value bypasses the provided function and continues matching
|
|
1269
1269
|
* through later cases.
|
|
1270
1270
|
*
|
|
1271
|
-
* **Example** (Ignoring a
|
|
1271
|
+
* **Example** (Ignoring a specific value)
|
|
1272
1272
|
*
|
|
1273
1273
|
* ```ts
|
|
1274
1274
|
* import { Match } from "effect"
|
|
@@ -1945,7 +1945,7 @@ export const instanceOfUnsafe: <A extends abstract new(...args: any) => any>(
|
|
|
1945
1945
|
* `default` clause in a `switch` statement or the final `else` in an `if-else`
|
|
1946
1946
|
* chain.
|
|
1947
1947
|
*
|
|
1948
|
-
* **Example** (Providing a
|
|
1948
|
+
* **Example** (Providing a default value when no patterns match)
|
|
1949
1949
|
*
|
|
1950
1950
|
* ```ts
|
|
1951
1951
|
* import { Match } from "effect"
|
|
@@ -2041,7 +2041,7 @@ export const orElseAbsurd: <I, R, RA, A, Pr, Ret>(
|
|
|
2041
2041
|
* unmatched case should be explicitly handled rather than returning a default
|
|
2042
2042
|
* value or throwing an error.
|
|
2043
2043
|
*
|
|
2044
|
-
* **Example** (Extracting a
|
|
2044
|
+
* **Example** (Extracting a user role with `Match.result`)
|
|
2045
2045
|
*
|
|
2046
2046
|
* ```ts
|
|
2047
2047
|
* import { Match } from "effect"
|
|
@@ -2087,7 +2087,7 @@ export const result: <I, F, R, A, Pr, Ret>(
|
|
|
2087
2087
|
* handled explicitly rather than throwing an error or returning a default
|
|
2088
2088
|
* value.
|
|
2089
2089
|
*
|
|
2090
|
-
* **Example** (Extracting a
|
|
2090
|
+
* **Example** (Extracting a user role with `Match.option`)
|
|
2091
2091
|
*
|
|
2092
2092
|
* ```ts
|
|
2093
2093
|
* import { Match } from "effect"
|
|
@@ -2131,7 +2131,7 @@ export const option: <I, F, R, A, Pr, Ret>(
|
|
|
2131
2131
|
* If any case is still unmatched, the matcher does not type-check as
|
|
2132
2132
|
* exhaustive.
|
|
2133
2133
|
*
|
|
2134
|
-
* **Example** (Ensuring
|
|
2134
|
+
* **Example** (Ensuring all cases are covered)
|
|
2135
2135
|
*
|
|
2136
2136
|
* ```ts
|
|
2137
2137
|
* import { Match } from "effect"
|
package/src/Metric.ts
CHANGED
|
@@ -1586,7 +1586,7 @@ export declare namespace Metric {
|
|
|
1586
1586
|
/**
|
|
1587
1587
|
* Service key for the current metric attributes context.
|
|
1588
1588
|
*
|
|
1589
|
-
* **Example** (
|
|
1589
|
+
* **Example** (Accessing the current metric attributes key)
|
|
1590
1590
|
*
|
|
1591
1591
|
* ```ts
|
|
1592
1592
|
* import { Data, Effect, Metric } from "effect"
|
|
@@ -4634,7 +4634,7 @@ const fiberFailures = counter("child_fiber_failures", {
|
|
|
4634
4634
|
/**
|
|
4635
4635
|
* Service key for the fiber runtime metrics service.
|
|
4636
4636
|
*
|
|
4637
|
-
* **Example** (
|
|
4637
|
+
* **Example** (Accessing the fiber runtime metrics key)
|
|
4638
4638
|
*
|
|
4639
4639
|
* ```ts
|
|
4640
4640
|
* import { Data, Effect, Layer, Metric } from "effect"
|
|
@@ -4781,7 +4781,7 @@ export const FiberRuntimeMetrics = Context.Reference<FiberRuntimeMetricsService
|
|
|
4781
4781
|
/**
|
|
4782
4782
|
* Default implementation of the fiber runtime metrics service.
|
|
4783
4783
|
*
|
|
4784
|
-
* **Example** (
|
|
4784
|
+
* **Example** (Accessing the default fiber metrics implementation)
|
|
4785
4785
|
*
|
|
4786
4786
|
* ```ts
|
|
4787
4787
|
* import { Data, Effect, Layer, Metric } from "effect"
|
package/src/Optic.ts
CHANGED
|
@@ -39,7 +39,7 @@ import type { IsUnion } from "./Types.ts"
|
|
|
39
39
|
* - `get(set(a)) === a` and `set(get(s))` equals `s` (round-trip laws).
|
|
40
40
|
* - Extends both {@link Lens} and {@link Prism}.
|
|
41
41
|
*
|
|
42
|
-
* **Example** (Celsius
|
|
42
|
+
* **Example** (Converting between Celsius and Fahrenheit)
|
|
43
43
|
*
|
|
44
44
|
* ```ts
|
|
45
45
|
* import { Optic } from "effect"
|
|
@@ -77,7 +77,7 @@ export interface Iso<in out S, in out A> extends Lens<S, A>, Prism<S, A> {}
|
|
|
77
77
|
*
|
|
78
78
|
* The returned optic can be composed with any other optic.
|
|
79
79
|
*
|
|
80
|
-
* **Example** (
|
|
80
|
+
* **Example** (Wrapping and unwrapping a branded type)
|
|
81
81
|
*
|
|
82
82
|
* ```ts
|
|
83
83
|
* import { Optic } from "effect"
|
|
@@ -121,7 +121,7 @@ export function makeIso<S, A>(get: (s: S) => A, set: (a: A) => S): Iso<S, A> {
|
|
|
121
121
|
* - Composing a Lens with a {@link Prism} or {@link Optional} produces an
|
|
122
122
|
* {@link Optional}.
|
|
123
123
|
*
|
|
124
|
-
* **Example** (
|
|
124
|
+
* **Example** (Focusing on a struct field)
|
|
125
125
|
*
|
|
126
126
|
* ```ts
|
|
127
127
|
* import { Optic } from "effect"
|
|
@@ -158,7 +158,7 @@ export interface Lens<in out S, in out A> extends Optional<S, A> {
|
|
|
158
158
|
* - `replace(a, s)` should return a structurally new `S` with `a` in place
|
|
159
159
|
* of the old focus.
|
|
160
160
|
*
|
|
161
|
-
* **Example** (
|
|
161
|
+
* **Example** (Focusing on the first element of a pair)
|
|
162
162
|
*
|
|
163
163
|
* ```ts
|
|
164
164
|
* import { Optic } from "effect"
|
|
@@ -204,7 +204,7 @@ export function makeLens<S, A>(get: (s: S) => A, replace: (a: A, s: S) => S): Le
|
|
|
204
204
|
* - Composing two Prisms produces a Prism; composing a Prism with a
|
|
205
205
|
* {@link Lens} produces an {@link Optional}.
|
|
206
206
|
*
|
|
207
|
-
* **Example** (
|
|
207
|
+
* **Example** (Narrowing a tagged union)
|
|
208
208
|
*
|
|
209
209
|
* ```ts
|
|
210
210
|
* import { Optic, Result } from "effect"
|
|
@@ -245,7 +245,7 @@ export interface Prism<in out S, in out A> extends Optional<S, A> {
|
|
|
245
245
|
*
|
|
246
246
|
* - `getResult` should return `Result.fail(message)` on mismatch.
|
|
247
247
|
*
|
|
248
|
-
* **Example** (
|
|
248
|
+
* **Example** (Parsing a string to a number)
|
|
249
249
|
*
|
|
250
250
|
* ```ts
|
|
251
251
|
* import { Optic, Result } from "effect"
|
|
@@ -290,7 +290,7 @@ export function makePrism<S, A>(getResult: (s: S) => Result.Result<A, string>, s
|
|
|
290
290
|
* any check fails.
|
|
291
291
|
* - `set` is identity — the value passes through unchanged.
|
|
292
292
|
*
|
|
293
|
-
* **Example** (positive integer prism)
|
|
293
|
+
* **Example** (Creating a positive integer prism)
|
|
294
294
|
*
|
|
295
295
|
* ```ts
|
|
296
296
|
* import { Optic, Result, Schema } from "effect"
|
|
@@ -473,7 +473,7 @@ type ForbidUnion<A, Message extends string> = IsUnion<A> extends true ? [Message
|
|
|
473
473
|
* - `modify(f)` returns the original `s` on failure (never throws).
|
|
474
474
|
* - All operations are pure; inputs are never mutated.
|
|
475
475
|
*
|
|
476
|
-
* **Example** (
|
|
476
|
+
* **Example** (Focusing on an optional record key)
|
|
477
477
|
*
|
|
478
478
|
* ```ts
|
|
479
479
|
* import { Optic, Result } from "effect"
|
|
@@ -521,7 +521,7 @@ export interface Optional<in out S, in out A> {
|
|
|
521
521
|
* Composes this optic with another. The result type is the weakest of
|
|
522
522
|
* the two: Iso + Iso = Iso, Lens + Prism = Optional, etc.
|
|
523
523
|
*
|
|
524
|
-
* **Example** (
|
|
524
|
+
* **Example** (Composing a lens with a prism)
|
|
525
525
|
*
|
|
526
526
|
* ```ts
|
|
527
527
|
* import { Optic, Option } from "effect"
|
|
@@ -543,7 +543,7 @@ export interface Optional<in out S, in out A> {
|
|
|
543
543
|
* Returns a function `(s: S) => S` that applies `f` to the focused value.
|
|
544
544
|
* If the optic cannot focus, the original `s` is returned unchanged.
|
|
545
545
|
*
|
|
546
|
-
* **Example** (
|
|
546
|
+
* **Example** (Incrementing a nested field)
|
|
547
547
|
*
|
|
548
548
|
* ```ts
|
|
549
549
|
* import { Optic } from "effect"
|
|
@@ -567,7 +567,7 @@ export interface Optional<in out S, in out A> {
|
|
|
567
567
|
* - On an {@link Optional}, returns an Optional.
|
|
568
568
|
* - Does **not** work on union types (compile error).
|
|
569
569
|
*
|
|
570
|
-
* **Example** (
|
|
570
|
+
* **Example** (Drilling into nested structs)
|
|
571
571
|
*
|
|
572
572
|
* ```ts
|
|
573
573
|
* import { Optic } from "effect"
|
|
@@ -599,7 +599,7 @@ export interface Optional<in out S, in out A> {
|
|
|
599
599
|
* - The focus type becomes `A[Key] | undefined`.
|
|
600
600
|
* - Does **not** work on union types (compile error).
|
|
601
601
|
*
|
|
602
|
-
* **Example** (
|
|
602
|
+
* **Example** (Deleting an optional key)
|
|
603
603
|
*
|
|
604
604
|
* ```ts
|
|
605
605
|
* import { Optic } from "effect"
|
|
@@ -634,7 +634,7 @@ export interface Optional<in out S, in out A> {
|
|
|
634
634
|
* - On a {@link Prism}, returns a Prism.
|
|
635
635
|
* - On an {@link Optional}, returns an Optional.
|
|
636
636
|
*
|
|
637
|
-
* **Example** (only
|
|
637
|
+
* **Example** (Focusing only on positive numbers)
|
|
638
638
|
*
|
|
639
639
|
* ```ts
|
|
640
640
|
* import { Optic, Result, Schema } from "effect"
|
|
@@ -665,7 +665,7 @@ export interface Optional<in out S, in out A> {
|
|
|
665
665
|
* - On an {@link Optional}, returns an Optional.
|
|
666
666
|
* - Pass optional `annotations` to customize the error message.
|
|
667
667
|
*
|
|
668
|
-
* **Example** (
|
|
668
|
+
* **Example** (Narrowing a union)
|
|
669
669
|
*
|
|
670
670
|
* ```ts
|
|
671
671
|
* import { Optic, Result } from "effect"
|
|
@@ -705,7 +705,7 @@ export interface Optional<in out S, in out A> {
|
|
|
705
705
|
* - On an {@link Optional}, returns an Optional.
|
|
706
706
|
* - Shorthand for `.refine(s => s._tag === tag)`.
|
|
707
707
|
*
|
|
708
|
-
* **Example** (
|
|
708
|
+
* **Example** (Focusing a tagged variant)
|
|
709
709
|
*
|
|
710
710
|
* ```ts
|
|
711
711
|
* import { Optic, Result } from "effect"
|
|
@@ -746,7 +746,7 @@ export interface Optional<in out S, in out A> {
|
|
|
746
746
|
* - Always returns an {@link Optional}.
|
|
747
747
|
* - Does **not** work on union types (compile error).
|
|
748
748
|
*
|
|
749
|
-
* **Example** (
|
|
749
|
+
* **Example** (Accessing records safely)
|
|
750
750
|
*
|
|
751
751
|
* ```ts
|
|
752
752
|
* import { Optic, Result } from "effect"
|
|
@@ -778,7 +778,7 @@ export interface Optional<in out S, in out A> {
|
|
|
778
778
|
* - On an {@link Optional}, returns an Optional.
|
|
779
779
|
* - Does **not** work on union types (compile error).
|
|
780
780
|
*
|
|
781
|
-
* **Example** (
|
|
781
|
+
* **Example** (Picking keys)
|
|
782
782
|
*
|
|
783
783
|
* ```ts
|
|
784
784
|
* import { Optic } from "effect"
|
|
@@ -813,7 +813,7 @@ export interface Optional<in out S, in out A> {
|
|
|
813
813
|
* - On an {@link Optional}, returns an Optional.
|
|
814
814
|
* - Does **not** work on union types (compile error).
|
|
815
815
|
*
|
|
816
|
-
* **Example** (
|
|
816
|
+
* **Example** (Omitting keys)
|
|
817
817
|
*
|
|
818
818
|
* ```ts
|
|
819
819
|
* import { Optic } from "effect"
|
|
@@ -845,7 +845,7 @@ export interface Optional<in out S, in out A> {
|
|
|
845
845
|
* Filters out `undefined` from the focus, producing a {@link Prism}.
|
|
846
846
|
* `getResult` fails when the focus is `undefined`.
|
|
847
847
|
*
|
|
848
|
-
* **Example** (
|
|
848
|
+
* **Example** (Filtering undefined values)
|
|
849
849
|
*
|
|
850
850
|
* ```ts
|
|
851
851
|
* import { Optic, Result } from "effect"
|
|
@@ -879,7 +879,7 @@ export interface Optional<in out S, in out A> {
|
|
|
879
879
|
* `getResult` and writes them back in order. Fails with a
|
|
880
880
|
* length-mismatch error if counts differ.
|
|
881
881
|
*
|
|
882
|
-
* **Example** (
|
|
882
|
+
* **Example** (Incrementing liked posts)
|
|
883
883
|
*
|
|
884
884
|
* ```ts
|
|
885
885
|
* import { Optic, Schema } from "effect"
|
|
@@ -918,7 +918,7 @@ export interface Optional<in out S, in out A> {
|
|
|
918
918
|
* Unlike `.modify()`, which operates on the whole array, `modifyAll`
|
|
919
919
|
* maps `f` over each individual element.
|
|
920
920
|
*
|
|
921
|
-
* **Example** (
|
|
921
|
+
* **Example** (Doubling all focused values)
|
|
922
922
|
*
|
|
923
923
|
* ```ts
|
|
924
924
|
* import { Optic, Schema } from "effect"
|
|
@@ -955,7 +955,7 @@ export interface Optional<in out S, in out A> {
|
|
|
955
955
|
* - `set` should return `Result.fail(message)` when the update cannot be
|
|
956
956
|
* applied.
|
|
957
957
|
*
|
|
958
|
-
* **Example** (
|
|
958
|
+
* **Example** (Accessing record keys safely)
|
|
959
959
|
*
|
|
960
960
|
* ```ts
|
|
961
961
|
* import { Optic, Result } from "effect"
|
|
@@ -1007,7 +1007,7 @@ export function makeOptional<S, A>(
|
|
|
1007
1007
|
* - Use `.modifyAll(f)` to map a function over every focused element.
|
|
1008
1008
|
* - Use {@link getAll} to extract all focused elements as a plain array.
|
|
1009
1009
|
*
|
|
1010
|
-
* **Example** (
|
|
1010
|
+
* **Example** (Traversing array elements with a filter)
|
|
1011
1011
|
*
|
|
1012
1012
|
* ```ts
|
|
1013
1013
|
* import { Optic, Schema } from "effect"
|
|
@@ -1397,7 +1397,7 @@ function getCompositionTag(a: Op["_tag"], b: Op["_tag"]): Op["_tag"] {
|
|
|
1397
1397
|
* - Returns an empty array when the traversal cannot focus.
|
|
1398
1398
|
* - Always returns a fresh array (safe to mutate).
|
|
1399
1399
|
*
|
|
1400
|
-
* **Example** (
|
|
1400
|
+
* **Example** (Collecting positive numbers)
|
|
1401
1401
|
*
|
|
1402
1402
|
* ```ts
|
|
1403
1403
|
* import { Optic, Schema } from "effect"
|
|
@@ -1449,7 +1449,7 @@ const identityIso = make(identityNode)
|
|
|
1449
1449
|
* - `set(a)` returns `a`.
|
|
1450
1450
|
* - Singleton — every call returns the same instance.
|
|
1451
1451
|
*
|
|
1452
|
-
* **Example** (
|
|
1452
|
+
* **Example** (Starting an optic chain)
|
|
1453
1453
|
*
|
|
1454
1454
|
* ```ts
|
|
1455
1455
|
* import { Optic } from "effect"
|
|
@@ -1486,7 +1486,7 @@ export function id<S>(): Iso<S, S> {
|
|
|
1486
1486
|
* - `set` uses `Object.fromEntries`.
|
|
1487
1487
|
* - Round-trip is lossless for `Record<string, A>`.
|
|
1488
1488
|
*
|
|
1489
|
-
* **Example** (
|
|
1489
|
+
* **Example** (Traversing record values)
|
|
1490
1490
|
*
|
|
1491
1491
|
* ```ts
|
|
1492
1492
|
* import { Optic, Schema } from "effect"
|
|
@@ -1523,7 +1523,7 @@ export function entries<A>(): Iso<Record<string, A>, ReadonlyArray<readonly [str
|
|
|
1523
1523
|
* - `getResult` fails with an error message when the option is `None`.
|
|
1524
1524
|
* - `set(a)` wraps `a` in `Option.some(a)`.
|
|
1525
1525
|
*
|
|
1526
|
-
* **Example** (
|
|
1526
|
+
* **Example** (Accessing Some value)
|
|
1527
1527
|
*
|
|
1528
1528
|
* ```ts
|
|
1529
1529
|
* import { Optic, Option, Result } from "effect"
|
|
@@ -1571,7 +1571,7 @@ export function some<A>(): Prism<Option.Option<A>, A> {
|
|
|
1571
1571
|
* - `getResult` fails when the option is `Some`.
|
|
1572
1572
|
* - `set(undefined)` produces `Option.none()`.
|
|
1573
1573
|
*
|
|
1574
|
-
* **Example** (
|
|
1574
|
+
* **Example** (Matching None)
|
|
1575
1575
|
*
|
|
1576
1576
|
* ```ts
|
|
1577
1577
|
* import { Optic, Option, Result } from "effect"
|
|
@@ -1616,7 +1616,7 @@ export function none<A>(): Prism<Option.Option<A>, undefined> {
|
|
|
1616
1616
|
* - `getResult` fails when the result is a `Failure`.
|
|
1617
1617
|
* - `set(a)` produces `Result.succeed(a)`.
|
|
1618
1618
|
*
|
|
1619
|
-
* **Example** (
|
|
1619
|
+
* **Example** (Accessing success)
|
|
1620
1620
|
*
|
|
1621
1621
|
* ```ts
|
|
1622
1622
|
* import { Optic, Result } from "effect"
|
|
@@ -1661,7 +1661,7 @@ export function success<A, E>(): Prism<Result.Result<A, E>, A> {
|
|
|
1661
1661
|
* - `getResult` fails when the result is a `Success`.
|
|
1662
1662
|
* - `set(e)` produces `Result.fail(e)`.
|
|
1663
1663
|
*
|
|
1664
|
-
* **Example** (
|
|
1664
|
+
* **Example** (Accessing failure)
|
|
1665
1665
|
*
|
|
1666
1666
|
* ```ts
|
|
1667
1667
|
* import { Optic, Result } from "effect"
|
package/src/Option.ts
CHANGED
|
@@ -1119,7 +1119,7 @@ export const firstSomeOf = <T, C extends Iterable<Option<T>> = Iterable<Option<T
|
|
|
1119
1119
|
* - `null` or `undefined` → `None`
|
|
1120
1120
|
* - Any other value → `Some` (typed as `NonNullable<A>`)
|
|
1121
1121
|
*
|
|
1122
|
-
* **Example** (
|
|
1122
|
+
* **Example** (Converting nullable values to an Option)
|
|
1123
1123
|
*
|
|
1124
1124
|
* ```ts
|
|
1125
1125
|
* import { Option } from "effect"
|
|
@@ -1159,7 +1159,7 @@ export const fromNullishOr = <A>(
|
|
|
1159
1159
|
* - `undefined` → `None`
|
|
1160
1160
|
* - Any other value (including `null`) → `Some`
|
|
1161
1161
|
*
|
|
1162
|
-
* **Example** (
|
|
1162
|
+
* **Example** (Converting possibly undefined values to an Option)
|
|
1163
1163
|
*
|
|
1164
1164
|
* ```ts
|
|
1165
1165
|
* import { Option } from "effect"
|
|
@@ -1198,7 +1198,7 @@ export const fromUndefinedOr = <A>(
|
|
|
1198
1198
|
* - `null` → `None`
|
|
1199
1199
|
* - Any other value (including `undefined`) → `Some`
|
|
1200
1200
|
*
|
|
1201
|
-
* **Example** (
|
|
1201
|
+
* **Example** (Converting possibly null values to an Option)
|
|
1202
1202
|
*
|
|
1203
1203
|
* ```ts
|
|
1204
1204
|
* import { Option } from "effect"
|
|
@@ -1733,7 +1733,7 @@ export {
|
|
|
1733
1733
|
*
|
|
1734
1734
|
* Use to return a "success with no meaningful value" from an `Option`-returning function
|
|
1735
1735
|
*
|
|
1736
|
-
* **Example** (
|
|
1736
|
+
* **Example** (Referencing Option.void)
|
|
1737
1737
|
*
|
|
1738
1738
|
* ```ts
|
|
1739
1739
|
* import { Option } from "effect"
|
|
@@ -3995,7 +3995,7 @@ export const liftPredicate: { // Note: I intentionally avoid using the NoInfer p
|
|
|
3995
3995
|
* - `Some` where `isEquivalent(value, a)` is `true` → `true`
|
|
3996
3996
|
* - `Some` where not equivalent, or `None` → `false`
|
|
3997
3997
|
*
|
|
3998
|
-
* **Example** (
|
|
3998
|
+
* **Example** (Checking with custom equivalence)
|
|
3999
3999
|
*
|
|
4000
4000
|
* ```ts
|
|
4001
4001
|
* import { Equivalence, Option } from "effect"
|
|
@@ -4595,7 +4595,7 @@ export const bind: {
|
|
|
4595
4595
|
* Use when you need to start an `Option` do notation pipeline before adding
|
|
4596
4596
|
* bindings.
|
|
4597
4597
|
*
|
|
4598
|
-
* **Example** (
|
|
4598
|
+
* **Example** (Building Option pipelines with do notation)
|
|
4599
4599
|
*
|
|
4600
4600
|
* ```ts
|
|
4601
4601
|
* import { Option, pipe } from "effect"
|
|
@@ -4635,7 +4635,7 @@ export const Do: Option<{}> = some({})
|
|
|
4635
4635
|
* - The return value is wrapped in `Some`
|
|
4636
4636
|
* - No `Effect` runtime is needed
|
|
4637
4637
|
*
|
|
4638
|
-
* **Example** (
|
|
4638
|
+
* **Example** (Sequencing Option computations with generator syntax)
|
|
4639
4639
|
*
|
|
4640
4640
|
* ```ts
|
|
4641
4641
|
* import { Option } from "effect"
|