effect 3.1.5 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Array.js +139 -2
- package/dist/cjs/Array.js.map +1 -1
- package/dist/cjs/Cause.js +8 -1
- package/dist/cjs/Cause.js.map +1 -1
- package/dist/cjs/Chunk.js +18 -1
- package/dist/cjs/Chunk.js.map +1 -1
- package/dist/cjs/Config.js.map +1 -1
- package/dist/cjs/Data.js +11 -8
- package/dist/cjs/Data.js.map +1 -1
- package/dist/cjs/Effect.js +106 -18
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/Stream.js +19 -1
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/Tracer.js.map +1 -1
- package/dist/cjs/internal/cause.js +55 -48
- package/dist/cjs/internal/cause.js.map +1 -1
- package/dist/cjs/internal/channel.js +11 -1
- package/dist/cjs/internal/channel.js.map +1 -1
- package/dist/cjs/internal/core-effect.js +51 -9
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/core.js +8 -4
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/fiberRuntime.js +27 -14
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/layer/circular.js +4 -1
- package/dist/cjs/internal/layer/circular.js.map +1 -1
- package/dist/cjs/internal/layer.js +11 -1
- package/dist/cjs/internal/layer.js.map +1 -1
- package/dist/cjs/internal/runtime.js +9 -4
- package/dist/cjs/internal/runtime.js.map +1 -1
- package/dist/cjs/internal/schedule.js +2 -2
- package/dist/cjs/internal/schedule.js.map +1 -1
- package/dist/cjs/internal/stream.js +27 -9
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/tracer.js +31 -1
- package/dist/cjs/internal/tracer.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Array.d.ts +199 -0
- package/dist/dts/Array.d.ts.map +1 -1
- package/dist/dts/Cause.d.ts +15 -0
- package/dist/dts/Cause.d.ts.map +1 -1
- package/dist/dts/Chunk.d.ts +20 -0
- package/dist/dts/Chunk.d.ts.map +1 -1
- package/dist/dts/Config.d.ts +6 -2
- package/dist/dts/Config.d.ts.map +1 -1
- package/dist/dts/Data.d.ts +46 -13
- package/dist/dts/Data.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +122 -15
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/Stream.d.ts +23 -1
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/Tracer.d.ts +1 -0
- package/dist/dts/Tracer.d.ts.map +1 -1
- package/dist/dts/internal/core-effect.d.ts +7 -1
- package/dist/dts/internal/core-effect.d.ts.map +1 -1
- package/dist/dts/internal/core.d.ts.map +1 -1
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/Array.js +182 -0
- package/dist/esm/Array.js.map +1 -1
- package/dist/esm/Cause.js +7 -0
- package/dist/esm/Cause.js.map +1 -1
- package/dist/esm/Chunk.js +16 -0
- package/dist/esm/Chunk.js.map +1 -1
- package/dist/esm/Config.js.map +1 -1
- package/dist/esm/Data.js +11 -8
- package/dist/esm/Data.js.map +1 -1
- package/dist/esm/Effect.js +103 -15
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/Stream.js +18 -0
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/Tracer.js.map +1 -1
- package/dist/esm/internal/cause.js +54 -47
- package/dist/esm/internal/cause.js.map +1 -1
- package/dist/esm/internal/channel.js +10 -1
- package/dist/esm/internal/channel.js.map +1 -1
- package/dist/esm/internal/core-effect.js +47 -7
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/core.js +7 -3
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/fiberRuntime.js +26 -14
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/layer/circular.js +4 -1
- package/dist/esm/internal/layer/circular.js.map +1 -1
- package/dist/esm/internal/layer.js +10 -1
- package/dist/esm/internal/layer.js.map +1 -1
- package/dist/esm/internal/runtime.js +9 -4
- package/dist/esm/internal/runtime.js.map +1 -1
- package/dist/esm/internal/schedule.js +2 -2
- package/dist/esm/internal/schedule.js.map +1 -1
- package/dist/esm/internal/stream.js +23 -7
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/tracer.js +29 -0
- package/dist/esm/internal/tracer.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Array.ts +214 -0
- package/src/Cause.ts +17 -0
- package/src/Chunk.ts +30 -0
- package/src/Config.ts +8 -6
- package/src/Data.ts +121 -48
- package/src/Effect.ts +126 -15
- package/src/Stream.ts +31 -1
- package/src/Tracer.ts +1 -0
- package/src/internal/cause.ts +70 -52
- package/src/internal/channel.ts +32 -14
- package/src/internal/core-effect.ts +74 -25
- package/src/internal/core.ts +8 -3
- package/src/internal/fiberRuntime.ts +22 -11
- package/src/internal/layer/circular.ts +4 -2
- package/src/internal/layer.ts +37 -14
- package/src/internal/runtime.ts +10 -5
- package/src/internal/schedule.ts +2 -2
- package/src/internal/stream.ts +37 -13
- package/src/internal/tracer.ts +21 -0
- package/src/internal/version.ts +1 -1
|
@@ -82,4 +82,33 @@ export const externalSpan = options => ({
|
|
|
82
82
|
sampled: options.sampled ?? true,
|
|
83
83
|
context: options.context ?? Context.empty()
|
|
84
84
|
});
|
|
85
|
+
/** @internal */
|
|
86
|
+
export const addSpanStackTrace = options => {
|
|
87
|
+
if (options?.captureStackTrace === false) {
|
|
88
|
+
return options;
|
|
89
|
+
} else if (options?.captureStackTrace !== undefined && typeof options.captureStackTrace !== "boolean") {
|
|
90
|
+
return options;
|
|
91
|
+
}
|
|
92
|
+
const limit = Error.stackTraceLimit;
|
|
93
|
+
Error.stackTraceLimit = 3;
|
|
94
|
+
const traceError = new Error();
|
|
95
|
+
Error.stackTraceLimit = limit;
|
|
96
|
+
if (traceError.stack === undefined) {
|
|
97
|
+
return {
|
|
98
|
+
...options,
|
|
99
|
+
captureStackTrace: false
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const stack = traceError.stack.split("\n");
|
|
103
|
+
if (!stack[3]) {
|
|
104
|
+
return {
|
|
105
|
+
...options,
|
|
106
|
+
captureStackTrace: false
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
...options,
|
|
111
|
+
captureStackTrace: stack[3].trim()
|
|
112
|
+
};
|
|
113
|
+
};
|
|
85
114
|
//# sourceMappingURL=tracer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracer.js","names":["Context","TracerTypeId","Symbol","for","make","options","tracerTag","GenericTag","spanTag","randomHexString","characters","charactersLength","length","result","i","charAt","Math","floor","random","NativeSpan","name","parent","context","links","startTime","kind","_tag","spanId","traceId","sampled","status","attributes","events","constructor","Map","value","end","endTime","exit","attribute","key","set","event","push","nativeTracer","span","f","externalSpan","empty"],"sources":["../../../src/internal/tracer.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,OAAO,MAAM,eAAe;AAKxC;AACA,OAAO,MAAMC,YAAY,gBAAwBC,MAAM,CAACC,GAAG,CAAC,eAAe,CAAwB;AAEnG;AACA,OAAO,MAAMC,IAAI,GAAIC,OAAiD,KAAqB;EACzF,CAACJ,YAAY,GAAGA,YAAY;EAC5B,GAAGI;CACJ,CAAC;AAEF;AACA,OAAO,MAAMC,SAAS,gBAAGN,OAAO,CAACO,UAAU,CAAgB,eAAe,CAAC;AAE3E;AACA,OAAO,MAAMC,OAAO,gBAAGR,OAAO,CAACO,UAAU,CAAoC,mBAAmB,CAAC;AAEjG,MAAME,eAAe,gBAAI;EACvB,MAAMC,UAAU,GAAG,kBAAkB;EACrC,MAAMC,gBAAgB,GAAGD,UAAU,CAACE,MAAM;EAC1C,OAAO,UAASA,MAAc;IAC5B,IAAIC,MAAM,GAAG,EAAE;IACf,KAAK,IAA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I,CAACM,MAAM,CAACN;KACxB;EACH;EAEAe,SAASA,CAACC,GAAW,EAAEL,KAAc;IACnC,IAAI,CAACJ,UAAU,CAACU,GAAG,CAACD,GAAG,EAAEL,KAAK,CAAC;EACjC;EAEAO,KAAKA,CAACtB,IAAY,EAAEI,SAAiB,EAAEO,UAAoC;IACzE,IAAI,CAACC,MAAM,CAACW,IAAI,CAAC,CAACvB,IAAI,EAAEI,SAAS,EAAEO,UAAU,IAAI,EAAE,CAAC,CAAC;EACvD;;AAGF;AACA,OAAO,MAAMa,YAAY,gBAAkBxC,IAAI,CAAC;EAC9CyC,IAAI,EAAEA,CAACzB,IAAI,EAAEC,MAAM,EAAEC,OAAO,EAAEC,KAAK,EAAEC,SAAS,EAAEC,IAAI,KAClD,IAAIN,UAAU,CACZC,IAAI,EACJC,MAAM,EACNC,OAAO,EACPC,KAAK,EACLC,SAAS,EACTC,IAAI,CACL;EACHH,OAAO,EAAGwB,CAAC,IAAKA,CAAC;CAClB,CAAC;AAEF;AACA,OAAO,MAAMC,YAAY,GAAI1C,OAK5B,KAA2B;EAC1BqB,IAAI,EAAE,cAAc;EACpBC,MAAM,EAAEtB,OAAO,CAACsB,MAAM;EACtBC,OAAO,EAAEvB,OAAO,CAACuB,OAAO;EACxBC,OAAO,EAAExB,OAAO,CAACwB,OAAO,IAAI,IAAI;EAChCP,OAAO,EAAEjB,OAAO,CAACiB,OAAO,IAAItB,OAAO,CAACgD,KAAK;CAC1C,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"tracer.js","names":["Context","TracerTypeId","Symbol","for","make","options","tracerTag","GenericTag","spanTag","randomHexString","characters","charactersLength","length","result","i","charAt","Math","floor","random","NativeSpan","name","parent","context","links","startTime","kind","_tag","spanId","traceId","sampled","status","attributes","events","constructor","Map","value","end","endTime","exit","attribute","key","set","event","push","nativeTracer","span","f","externalSpan","empty","addSpanStackTrace","captureStackTrace","undefined","limit","Error","stackTraceLimit","traceError","stack","split","trim"],"sources":["../../../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 import type { LazyArg } from "./Function.js"
|
|
|
12
12
|
import { dual, identity } from "./Function.js"
|
|
13
13
|
import type { TypeLambda } from "./HKT.js"
|
|
14
14
|
import * as readonlyArray from "./internal/array.js"
|
|
15
|
+
import * as doNotation from "./internal/doNotation.js"
|
|
15
16
|
import * as EffectIterable from "./Iterable.js"
|
|
16
17
|
import type { Option } from "./Option.js"
|
|
17
18
|
import * as O from "./Option.js"
|
|
@@ -2111,3 +2112,216 @@ export const cartesian: {
|
|
|
2111
2112
|
2,
|
|
2112
2113
|
<A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]> => cartesianWith(self, that, (a, b) => [a, b])
|
|
2113
2114
|
)
|
|
2115
|
+
|
|
2116
|
+
// -------------------------------------------------------------------------------------
|
|
2117
|
+
// do notation
|
|
2118
|
+
// -------------------------------------------------------------------------------------
|
|
2119
|
+
|
|
2120
|
+
/**
|
|
2121
|
+
* The "do simulation" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.
|
|
2122
|
+
*
|
|
2123
|
+
* It can be used to simulate "array comprehension".
|
|
2124
|
+
* It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.
|
|
2125
|
+
*
|
|
2126
|
+
* Here's how the do simulation works:
|
|
2127
|
+
*
|
|
2128
|
+
* 1. Start the do simulation using the `Do` value
|
|
2129
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values
|
|
2130
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
2131
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
2132
|
+
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
2133
|
+
*
|
|
2134
|
+
* @see {@link bindTo}
|
|
2135
|
+
* @see {@link bind}
|
|
2136
|
+
* @see {@link let_ let}
|
|
2137
|
+
*
|
|
2138
|
+
* @example
|
|
2139
|
+
* import { Array as Arr, pipe } from "effect"
|
|
2140
|
+
* const doResult = pipe(
|
|
2141
|
+
* Arr.Do,
|
|
2142
|
+
* Arr.bind("x", () => [1, 3, 5]),
|
|
2143
|
+
* Arr.bind("y", () => [2, 4, 6]),
|
|
2144
|
+
* Arr.filter(({ x, y }) => x < y), // condition
|
|
2145
|
+
* Arr.map(({ x, y }) => [x, y] as const) // transformation
|
|
2146
|
+
* )
|
|
2147
|
+
* assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])
|
|
2148
|
+
*
|
|
2149
|
+
* // equivalent
|
|
2150
|
+
* const x = [1, 3, 5],
|
|
2151
|
+
* y = [2, 4, 6],
|
|
2152
|
+
* result = [];
|
|
2153
|
+
* for(let i = 0; i < x.length; i++) {
|
|
2154
|
+
* for(let j = 0; j < y.length; j++) {
|
|
2155
|
+
* const _x = x[i], _y = y[j];
|
|
2156
|
+
* if(_x < _y) result.push([_x, _y] as const)
|
|
2157
|
+
* }
|
|
2158
|
+
* }
|
|
2159
|
+
*
|
|
2160
|
+
* @category do notation
|
|
2161
|
+
* @since 3.2.0
|
|
2162
|
+
*/
|
|
2163
|
+
export const Do: ReadonlyArray<{}> = of({})
|
|
2164
|
+
|
|
2165
|
+
/**
|
|
2166
|
+
* The "do simulation" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.
|
|
2167
|
+
*
|
|
2168
|
+
* It can be used to simulate "array comprehension".
|
|
2169
|
+
* It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.
|
|
2170
|
+
*
|
|
2171
|
+
* Here's how the do simulation works:
|
|
2172
|
+
*
|
|
2173
|
+
* 1. Start the do simulation using the `Do` value
|
|
2174
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values
|
|
2175
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
2176
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
2177
|
+
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
2178
|
+
*
|
|
2179
|
+
* @see {@link bindTo}
|
|
2180
|
+
* @see {@link Do}
|
|
2181
|
+
* @see {@link let_ let}
|
|
2182
|
+
*
|
|
2183
|
+
* @example
|
|
2184
|
+
* import { Array as Arr, pipe } from "effect"
|
|
2185
|
+
* const doResult = pipe(
|
|
2186
|
+
* Arr.Do,
|
|
2187
|
+
* Arr.bind("x", () => [1, 3, 5]),
|
|
2188
|
+
* Arr.bind("y", () => [2, 4, 6]),
|
|
2189
|
+
* Arr.filter(({ x, y }) => x < y), // condition
|
|
2190
|
+
* Arr.map(({ x, y }) => [x, y] as const) // transformation
|
|
2191
|
+
* )
|
|
2192
|
+
* assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])
|
|
2193
|
+
*
|
|
2194
|
+
* // equivalent
|
|
2195
|
+
* const x = [1, 3, 5],
|
|
2196
|
+
* y = [2, 4, 6],
|
|
2197
|
+
* result = [];
|
|
2198
|
+
* for(let i = 0; i < x.length; i++) {
|
|
2199
|
+
* for(let j = 0; j < y.length; j++) {
|
|
2200
|
+
* const _x = x[i], _y = y[j];
|
|
2201
|
+
* if(_x < _y) result.push([_x, _y] as const)
|
|
2202
|
+
* }
|
|
2203
|
+
* }
|
|
2204
|
+
*
|
|
2205
|
+
* @category do notation
|
|
2206
|
+
* @since 3.2.0
|
|
2207
|
+
*/
|
|
2208
|
+
export const bind: {
|
|
2209
|
+
<A extends object, N extends string, B>(
|
|
2210
|
+
tag: Exclude<N, keyof A>,
|
|
2211
|
+
f: (a: A) => ReadonlyArray<B>
|
|
2212
|
+
): (
|
|
2213
|
+
self: ReadonlyArray<A>
|
|
2214
|
+
) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>
|
|
2215
|
+
<A extends object, N extends string, B>(
|
|
2216
|
+
self: ReadonlyArray<A>,
|
|
2217
|
+
tag: Exclude<N, keyof A>,
|
|
2218
|
+
f: (a: A) => ReadonlyArray<B>
|
|
2219
|
+
): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>
|
|
2220
|
+
} = doNotation.bind<ReadonlyArrayTypeLambda>(map, flatMap) as any
|
|
2221
|
+
|
|
2222
|
+
/**
|
|
2223
|
+
* The "do simulation" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.
|
|
2224
|
+
*
|
|
2225
|
+
* It can be used to simulate "array comprehension".
|
|
2226
|
+
* It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.
|
|
2227
|
+
*
|
|
2228
|
+
* Here's how the do simulation works:
|
|
2229
|
+
*
|
|
2230
|
+
* 1. Start the do simulation using the `Do` value
|
|
2231
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values
|
|
2232
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
2233
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
2234
|
+
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
2235
|
+
*
|
|
2236
|
+
* @see {@link bindTo}
|
|
2237
|
+
* @see {@link Do}
|
|
2238
|
+
* @see {@link let_ let}
|
|
2239
|
+
*
|
|
2240
|
+
* @example
|
|
2241
|
+
* import { Array as Arr, pipe } from "effect"
|
|
2242
|
+
* const doResult = pipe(
|
|
2243
|
+
* Arr.Do,
|
|
2244
|
+
* Arr.bind("x", () => [1, 3, 5]),
|
|
2245
|
+
* Arr.bind("y", () => [2, 4, 6]),
|
|
2246
|
+
* Arr.filter(({ x, y }) => x < y), // condition
|
|
2247
|
+
* Arr.map(({ x, y }) => [x, y] as const) // transformation
|
|
2248
|
+
* )
|
|
2249
|
+
* assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])
|
|
2250
|
+
*
|
|
2251
|
+
* // equivalent
|
|
2252
|
+
* const x = [1, 3, 5],
|
|
2253
|
+
* y = [2, 4, 6],
|
|
2254
|
+
* result = [];
|
|
2255
|
+
* for(let i = 0; i < x.length; i++) {
|
|
2256
|
+
* for(let j = 0; j < y.length; j++) {
|
|
2257
|
+
* const _x = x[i], _y = y[j];
|
|
2258
|
+
* if(_x < _y) result.push([_x, _y] as const)
|
|
2259
|
+
* }
|
|
2260
|
+
* }
|
|
2261
|
+
*
|
|
2262
|
+
* @category do notation
|
|
2263
|
+
* @since 3.2.0
|
|
2264
|
+
*/
|
|
2265
|
+
export const bindTo: {
|
|
2266
|
+
<N extends string>(tag: N): <A>(self: ReadonlyArray<A>) => Array<{ [K in N]: A }>
|
|
2267
|
+
<A, N extends string>(self: ReadonlyArray<A>, tag: N): Array<{ [K in N]: A }>
|
|
2268
|
+
} = doNotation.bindTo<ReadonlyArrayTypeLambda>(map) as any
|
|
2269
|
+
|
|
2270
|
+
const let_: {
|
|
2271
|
+
<N extends string, B, A extends object>(
|
|
2272
|
+
tag: Exclude<N, keyof A>,
|
|
2273
|
+
f: (a: A) => B
|
|
2274
|
+
): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>
|
|
2275
|
+
<N extends string, A extends object, B>(
|
|
2276
|
+
self: ReadonlyArray<A>,
|
|
2277
|
+
tag: Exclude<N, keyof A>,
|
|
2278
|
+
f: (a: A) => B
|
|
2279
|
+
): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>
|
|
2280
|
+
} = doNotation.let_<ReadonlyArrayTypeLambda>(map) as any
|
|
2281
|
+
|
|
2282
|
+
export {
|
|
2283
|
+
/**
|
|
2284
|
+
* The "do simulation" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.
|
|
2285
|
+
*
|
|
2286
|
+
* It can be used to simulate "array comprehension".
|
|
2287
|
+
* It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.
|
|
2288
|
+
*
|
|
2289
|
+
* Here's how the do simulation works:
|
|
2290
|
+
*
|
|
2291
|
+
* 1. Start the do simulation using the `Do` value
|
|
2292
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values
|
|
2293
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
2294
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
2295
|
+
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
2296
|
+
*
|
|
2297
|
+
* @see {@link bindTo}
|
|
2298
|
+
* @see {@link bind}
|
|
2299
|
+
* @see {@link Do}
|
|
2300
|
+
*
|
|
2301
|
+
* @example
|
|
2302
|
+
* import { Array as Arr, pipe } from "effect"
|
|
2303
|
+
* const doResult = pipe(
|
|
2304
|
+
* Arr.Do,
|
|
2305
|
+
* Arr.bind("x", () => [1, 3, 5]),
|
|
2306
|
+
* Arr.bind("y", () => [2, 4, 6]),
|
|
2307
|
+
* Arr.filter(({ x, y }) => x < y), // condition
|
|
2308
|
+
* Arr.map(({ x, y }) => [x, y] as const) // transformation
|
|
2309
|
+
* )
|
|
2310
|
+
* assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])
|
|
2311
|
+
*
|
|
2312
|
+
* // equivalent
|
|
2313
|
+
* const x = [1, 3, 5],
|
|
2314
|
+
* y = [2, 4, 6],
|
|
2315
|
+
* result = [];
|
|
2316
|
+
* for(let i = 0; i < x.length; i++) {
|
|
2317
|
+
* for(let j = 0; j < y.length; j++) {
|
|
2318
|
+
* const _x = x[i], _y = y[j];
|
|
2319
|
+
* if(_x < _y) result.push([_x, _y] as const)
|
|
2320
|
+
* }
|
|
2321
|
+
* }
|
|
2322
|
+
*
|
|
2323
|
+
* @category do notation
|
|
2324
|
+
* @since 3.2.0
|
|
2325
|
+
*/
|
|
2326
|
+
let_ as let
|
|
2327
|
+
}
|
package/src/Cause.ts
CHANGED
|
@@ -36,6 +36,7 @@ import type { Pipeable } from "./Pipeable.js"
|
|
|
36
36
|
import type { Predicate, Refinement } from "./Predicate.js"
|
|
37
37
|
import type * as Sink from "./Sink.js"
|
|
38
38
|
import type * as Stream from "./Stream.js"
|
|
39
|
+
import type { Span } from "./Tracer.js"
|
|
39
40
|
import type { Covariant, NoInfer } from "./Types.js"
|
|
40
41
|
|
|
41
42
|
/**
|
|
@@ -914,6 +915,22 @@ export const isUnknownException: (u: unknown) => u is UnknownException = core.is
|
|
|
914
915
|
*/
|
|
915
916
|
export const pretty: <E>(cause: Cause<E>) => string = internal.pretty
|
|
916
917
|
|
|
918
|
+
/**
|
|
919
|
+
* @since 3.2.0
|
|
920
|
+
* @category models
|
|
921
|
+
*/
|
|
922
|
+
export interface PrettyError extends Error {
|
|
923
|
+
readonly span: Span | undefined
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* Returns the specified `Cause` as a pretty-printed string.
|
|
928
|
+
*
|
|
929
|
+
* @since 3.2.0
|
|
930
|
+
* @category rendering
|
|
931
|
+
*/
|
|
932
|
+
export const prettyErrors: <E>(cause: Cause<E>) => Array<PrettyError> = internal.prettyErrors
|
|
933
|
+
|
|
917
934
|
/**
|
|
918
935
|
* Returns the original, unproxied, instance of a thrown error
|
|
919
936
|
*
|
package/src/Chunk.ts
CHANGED
|
@@ -1387,3 +1387,33 @@ export const reduceRight: {
|
|
|
1387
1387
|
<B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => B
|
|
1388
1388
|
<A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): B
|
|
1389
1389
|
} = RA.reduceRight
|
|
1390
|
+
|
|
1391
|
+
/**
|
|
1392
|
+
* Creates a `Chunk` of values not included in the other given `Chunk` using the provided `isEquivalent` function.
|
|
1393
|
+
* The order and references of result values are determined by the first `Chunk`.
|
|
1394
|
+
*
|
|
1395
|
+
* @since 3.2.0
|
|
1396
|
+
*/
|
|
1397
|
+
export const differenceWith = <A>(isEquivalent: (self: A, that: A) => boolean): {
|
|
1398
|
+
(that: Chunk<A>): (self: Chunk<A>) => Chunk<A>
|
|
1399
|
+
(self: Chunk<A>, that: Chunk<A>): Chunk<A>
|
|
1400
|
+
} => {
|
|
1401
|
+
return dual(
|
|
1402
|
+
2,
|
|
1403
|
+
(self: Chunk<A>, that: Chunk<A>): Chunk<A> => unsafeFromArray(RA.differenceWith(isEquivalent)(that, self))
|
|
1404
|
+
)
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
/**
|
|
1408
|
+
* Creates a `Chunk` of values not included in the other given `Chunk`.
|
|
1409
|
+
* The order and references of result values are determined by the first `Chunk`.
|
|
1410
|
+
*
|
|
1411
|
+
* @since 3.2.0
|
|
1412
|
+
*/
|
|
1413
|
+
export const difference: {
|
|
1414
|
+
<A>(that: Chunk<A>): (self: Chunk<A>) => Chunk<A>
|
|
1415
|
+
<A>(self: Chunk<A>, that: Chunk<A>): Chunk<A>
|
|
1416
|
+
} = dual(
|
|
1417
|
+
2,
|
|
1418
|
+
<A>(self: Chunk<A>, that: Chunk<A>): Chunk<A> => unsafeFromArray(RA.difference(that, self))
|
|
1419
|
+
)
|
package/src/Config.ts
CHANGED
|
@@ -69,12 +69,14 @@ export declare namespace Config {
|
|
|
69
69
|
* @since 2.0.0
|
|
70
70
|
* @category models
|
|
71
71
|
*/
|
|
72
|
-
export type Wrap<A> =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
export type Wrap<A> = [A] extends [Function] ? Config<A> :
|
|
73
|
+
[A] extends [ReadonlyArray<infer _>] ? Config<A> :
|
|
74
|
+
[A] extends [Record<string, any>] ?
|
|
75
|
+
| {
|
|
76
|
+
[K in keyof A]: Wrap<A[K]>
|
|
77
|
+
}
|
|
78
|
+
| Config<A>
|
|
79
|
+
: Config<A>
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
/**
|
package/src/Data.ts
CHANGED
|
@@ -7,6 +7,7 @@ import * as internal from "./internal/data.js"
|
|
|
7
7
|
import { StructuralPrototype } from "./internal/effectable.js"
|
|
8
8
|
import * as Predicate from "./Predicate.js"
|
|
9
9
|
import type * as Types from "./Types.js"
|
|
10
|
+
import type { Unify } from "./Unify.js"
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @since 2.0.0
|
|
@@ -336,13 +337,63 @@ export declare namespace TaggedEnum {
|
|
|
336
337
|
}
|
|
337
338
|
& {
|
|
338
339
|
readonly $is: <Tag extends A["_tag"]>(tag: Tag) => (u: unknown) => u is Extract<A, { readonly _tag: Tag }>
|
|
339
|
-
readonly $match:
|
|
340
|
+
readonly $match: {
|
|
341
|
+
<
|
|
342
|
+
Cases extends {
|
|
343
|
+
readonly [Tag in A["_tag"]]: (args: Extract<A, { readonly _tag: Tag }>) => any
|
|
344
|
+
}
|
|
345
|
+
>(cases: Cases): (value: A) => Unify<ReturnType<Cases[A["_tag"]]>>
|
|
346
|
+
<
|
|
347
|
+
Cases extends {
|
|
348
|
+
readonly [Tag in A["_tag"]]: (args: Extract<A, { readonly _tag: Tag }>) => any
|
|
349
|
+
}
|
|
350
|
+
>(value: A, cases: Cases): Unify<ReturnType<Cases[A["_tag"]]>>
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
>
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* @since 3.2.0
|
|
357
|
+
*/
|
|
358
|
+
export interface GenericMatchers<Z extends WithGenerics<number>> {
|
|
359
|
+
readonly $is: <Tag extends Z["taggedEnum"]["_tag"]>(
|
|
360
|
+
tag: Tag
|
|
361
|
+
) => {
|
|
362
|
+
<T extends TaggedEnum.Kind<Z, any, any, any, any>>(
|
|
363
|
+
u: T
|
|
364
|
+
): u is T & { readonly _tag: Tag }
|
|
365
|
+
(u: unknown): u is Extract<TaggedEnum.Kind<Z>, { readonly _tag: Tag }>
|
|
366
|
+
}
|
|
367
|
+
readonly $match: {
|
|
368
|
+
<
|
|
369
|
+
A,
|
|
370
|
+
B,
|
|
371
|
+
C,
|
|
372
|
+
D,
|
|
373
|
+
Cases extends {
|
|
374
|
+
readonly [Tag in Z["taggedEnum"]["_tag"]]: (
|
|
375
|
+
args: Extract<TaggedEnum.Kind<Z, A, B, C, D>, { readonly _tag: Tag }>
|
|
376
|
+
) => any
|
|
377
|
+
}
|
|
378
|
+
>(
|
|
379
|
+
cases: Cases
|
|
380
|
+
): (self: TaggedEnum.Kind<Z, A, B, C, D>) => Unify<ReturnType<Cases[Z["taggedEnum"]["_tag"]]>>
|
|
381
|
+
<
|
|
382
|
+
A,
|
|
383
|
+
B,
|
|
384
|
+
C,
|
|
385
|
+
D,
|
|
340
386
|
Cases extends {
|
|
341
|
-
readonly [Tag in
|
|
387
|
+
readonly [Tag in Z["taggedEnum"]["_tag"]]: (
|
|
388
|
+
args: Extract<TaggedEnum.Kind<Z, A, B, C, D>, { readonly _tag: Tag }>
|
|
389
|
+
) => any
|
|
342
390
|
}
|
|
343
|
-
>(
|
|
391
|
+
>(
|
|
392
|
+
self: TaggedEnum.Kind<Z, A, B, C, D>,
|
|
393
|
+
cases: Cases
|
|
394
|
+
): Unify<ReturnType<Cases[Z["taggedEnum"]["_tag"]]>>
|
|
344
395
|
}
|
|
345
|
-
|
|
396
|
+
}
|
|
346
397
|
}
|
|
347
398
|
|
|
348
399
|
/**
|
|
@@ -379,52 +430,60 @@ export declare namespace TaggedEnum {
|
|
|
379
430
|
* @since 2.0.0
|
|
380
431
|
*/
|
|
381
432
|
export const taggedEnum: {
|
|
382
|
-
<Z extends TaggedEnum.WithGenerics<1>>():
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
TaggedEnum.
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
433
|
+
<Z extends TaggedEnum.WithGenerics<1>>(): Types.Simplify<
|
|
434
|
+
{
|
|
435
|
+
readonly [Tag in Z["taggedEnum"]["_tag"]]: <A>(
|
|
436
|
+
args: TaggedEnum.Args<
|
|
437
|
+
TaggedEnum.Kind<Z, A>,
|
|
438
|
+
Tag,
|
|
439
|
+
Extract<TaggedEnum.Kind<Z, A>, { readonly _tag: Tag }>
|
|
440
|
+
>
|
|
441
|
+
) => TaggedEnum.Value<TaggedEnum.Kind<Z, A>, Tag>
|
|
442
|
+
} & TaggedEnum.GenericMatchers<Z>
|
|
443
|
+
>
|
|
391
444
|
|
|
392
|
-
<Z extends TaggedEnum.WithGenerics<2>>():
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
TaggedEnum.
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
445
|
+
<Z extends TaggedEnum.WithGenerics<2>>(): Types.Simplify<
|
|
446
|
+
{
|
|
447
|
+
readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B>(
|
|
448
|
+
args: TaggedEnum.Args<
|
|
449
|
+
TaggedEnum.Kind<Z, A, B>,
|
|
450
|
+
Tag,
|
|
451
|
+
Extract<TaggedEnum.Kind<Z, A, B>, { readonly _tag: Tag }>
|
|
452
|
+
>
|
|
453
|
+
) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>
|
|
454
|
+
} & TaggedEnum.GenericMatchers<Z>
|
|
455
|
+
>
|
|
401
456
|
|
|
402
|
-
<Z extends TaggedEnum.WithGenerics<3>>():
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
TaggedEnum.
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
457
|
+
<Z extends TaggedEnum.WithGenerics<3>>(): Types.Simplify<
|
|
458
|
+
{
|
|
459
|
+
readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C>(
|
|
460
|
+
args: TaggedEnum.Args<
|
|
461
|
+
TaggedEnum.Kind<Z, A, B, C>,
|
|
462
|
+
Tag,
|
|
463
|
+
Extract<TaggedEnum.Kind<Z, A, B, C>, { readonly _tag: Tag }>
|
|
464
|
+
>
|
|
465
|
+
) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>
|
|
466
|
+
} & TaggedEnum.GenericMatchers<Z>
|
|
467
|
+
>
|
|
411
468
|
|
|
412
|
-
<Z extends TaggedEnum.WithGenerics<4>>():
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
TaggedEnum.
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
469
|
+
<Z extends TaggedEnum.WithGenerics<4>>(): Types.Simplify<
|
|
470
|
+
{
|
|
471
|
+
readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C, D>(
|
|
472
|
+
args: TaggedEnum.Args<
|
|
473
|
+
TaggedEnum.Kind<Z, A, B, C, D>,
|
|
474
|
+
Tag,
|
|
475
|
+
Extract<TaggedEnum.Kind<Z, A, B, C, D>, { readonly _tag: Tag }>
|
|
476
|
+
>
|
|
477
|
+
) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
|
|
478
|
+
} & TaggedEnum.GenericMatchers<Z>
|
|
479
|
+
>
|
|
421
480
|
|
|
422
481
|
<A extends { readonly _tag: string }>(): TaggedEnum.Constructor<A>
|
|
423
482
|
} = () =>
|
|
424
483
|
new Proxy({}, {
|
|
425
484
|
get(_target, tag, _receiver) {
|
|
426
485
|
if (tag === "$is") {
|
|
427
|
-
return
|
|
486
|
+
return Predicate.isTagged
|
|
428
487
|
} else if (tag === "$match") {
|
|
429
488
|
return taggedMatch
|
|
430
489
|
}
|
|
@@ -432,19 +491,33 @@ export const taggedEnum: {
|
|
|
432
491
|
}
|
|
433
492
|
}) as any
|
|
434
493
|
|
|
435
|
-
function taggedIs<A extends { readonly _tag: string }, Tag extends A["_tag"]>(tag: Tag) {
|
|
436
|
-
return Predicate.isTagged(tag)
|
|
437
|
-
}
|
|
438
|
-
|
|
439
494
|
function taggedMatch<
|
|
440
495
|
A extends { readonly _tag: string },
|
|
441
496
|
Cases extends {
|
|
442
497
|
readonly [K in A["_tag"]]: (args: Extract<A, { readonly _tag: K }>) => any
|
|
443
498
|
}
|
|
444
|
-
>(cases: Cases)
|
|
445
|
-
|
|
446
|
-
|
|
499
|
+
>(self: A, cases: Cases): ReturnType<Cases[A["_tag"]]>
|
|
500
|
+
function taggedMatch<
|
|
501
|
+
A extends { readonly _tag: string },
|
|
502
|
+
Cases extends {
|
|
503
|
+
readonly [K in A["_tag"]]: (args: Extract<A, { readonly _tag: K }>) => any
|
|
504
|
+
}
|
|
505
|
+
>(cases: Cases): (value: A) => ReturnType<Cases[A["_tag"]]>
|
|
506
|
+
function taggedMatch<
|
|
507
|
+
A extends { readonly _tag: string },
|
|
508
|
+
Cases extends {
|
|
509
|
+
readonly [K in A["_tag"]]: (args: Extract<A, { readonly _tag: K }>) => any
|
|
510
|
+
}
|
|
511
|
+
>(): any {
|
|
512
|
+
if (arguments.length === 1) {
|
|
513
|
+
const cases = arguments[0] as Cases
|
|
514
|
+
return function(value: A): ReturnType<Cases[A["_tag"]]> {
|
|
515
|
+
return cases[value._tag as A["_tag"]](value as any)
|
|
516
|
+
}
|
|
447
517
|
}
|
|
518
|
+
const value = arguments[0] as A
|
|
519
|
+
const cases = arguments[1] as Cases
|
|
520
|
+
return cases[value._tag as A["_tag"]](value as any)
|
|
448
521
|
}
|
|
449
522
|
|
|
450
523
|
/**
|