effect 3.0.2 → 3.0.4

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 (106) hide show
  1. package/dist/cjs/Cause.js.map +1 -1
  2. package/dist/cjs/Chunk.js +1 -1
  3. package/dist/cjs/Chunk.js.map +1 -1
  4. package/dist/cjs/Effect.js.map +1 -1
  5. package/dist/cjs/Either.js +4 -6
  6. package/dist/cjs/Either.js.map +1 -1
  7. package/dist/cjs/Match.js +6 -1
  8. package/dist/cjs/Match.js.map +1 -1
  9. package/dist/cjs/Option.js +3 -5
  10. package/dist/cjs/Option.js.map +1 -1
  11. package/dist/cjs/Order.js +15 -0
  12. package/dist/cjs/Order.js.map +1 -1
  13. package/dist/cjs/STM.js.map +1 -1
  14. package/dist/cjs/Utils.js +2 -4
  15. package/dist/cjs/Utils.js.map +1 -1
  16. package/dist/cjs/internal/core-effect.js +3 -21
  17. package/dist/cjs/internal/core-effect.js.map +1 -1
  18. package/dist/cjs/internal/core.js +10 -0
  19. package/dist/cjs/internal/core.js.map +1 -1
  20. package/dist/cjs/internal/effectable.js +4 -0
  21. package/dist/cjs/internal/effectable.js.map +1 -1
  22. package/dist/cjs/internal/fiberRuntime.js +3 -3
  23. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  24. package/dist/cjs/internal/matcher.js +8 -3
  25. package/dist/cjs/internal/matcher.js.map +1 -1
  26. package/dist/cjs/internal/rateLimiter.js +1 -1
  27. package/dist/cjs/internal/rateLimiter.js.map +1 -1
  28. package/dist/cjs/internal/stm/core.js +4 -0
  29. package/dist/cjs/internal/stm/core.js.map +1 -1
  30. package/dist/cjs/internal/stm/stm.js +3 -21
  31. package/dist/cjs/internal/stm/stm.js.map +1 -1
  32. package/dist/cjs/internal/version.js +1 -1
  33. package/dist/dts/Cause.d.ts +1 -0
  34. package/dist/dts/Cause.d.ts.map +1 -1
  35. package/dist/dts/Chunk.d.ts.map +1 -1
  36. package/dist/dts/Effect.d.ts +43 -38
  37. package/dist/dts/Effect.d.ts.map +1 -1
  38. package/dist/dts/Either.d.ts +1 -1
  39. package/dist/dts/Either.d.ts.map +1 -1
  40. package/dist/dts/Match.d.ts +35 -36
  41. package/dist/dts/Match.d.ts.map +1 -1
  42. package/dist/dts/Option.d.ts +1 -1
  43. package/dist/dts/Option.d.ts.map +1 -1
  44. package/dist/dts/Order.d.ts.map +1 -1
  45. package/dist/dts/STM.d.ts +25 -35
  46. package/dist/dts/STM.d.ts.map +1 -1
  47. package/dist/dts/Utils.d.ts +29 -25
  48. package/dist/dts/Utils.d.ts.map +1 -1
  49. package/dist/dts/index.d.ts +15 -0
  50. package/dist/dts/index.d.ts.map +1 -1
  51. package/dist/dts/internal/core.d.ts.map +1 -1
  52. package/dist/dts/internal/stm/stm.d.ts.map +1 -1
  53. package/dist/esm/Cause.js.map +1 -1
  54. package/dist/esm/Chunk.js +1 -1
  55. package/dist/esm/Chunk.js.map +1 -1
  56. package/dist/esm/Effect.js.map +1 -1
  57. package/dist/esm/Either.js +4 -6
  58. package/dist/esm/Either.js.map +1 -1
  59. package/dist/esm/Match.js +5 -0
  60. package/dist/esm/Match.js.map +1 -1
  61. package/dist/esm/Option.js +4 -6
  62. package/dist/esm/Option.js.map +1 -1
  63. package/dist/esm/Order.js +15 -0
  64. package/dist/esm/Order.js.map +1 -1
  65. package/dist/esm/STM.js.map +1 -1
  66. package/dist/esm/Utils.js +2 -4
  67. package/dist/esm/Utils.js.map +1 -1
  68. package/dist/esm/index.js +15 -0
  69. package/dist/esm/index.js.map +1 -1
  70. package/dist/esm/internal/core-effect.js +2 -20
  71. package/dist/esm/internal/core-effect.js.map +1 -1
  72. package/dist/esm/internal/core.js +10 -0
  73. package/dist/esm/internal/core.js.map +1 -1
  74. package/dist/esm/internal/effectable.js +4 -0
  75. package/dist/esm/internal/effectable.js.map +1 -1
  76. package/dist/esm/internal/fiberRuntime.js +3 -3
  77. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  78. package/dist/esm/internal/matcher.js +6 -2
  79. package/dist/esm/internal/matcher.js.map +1 -1
  80. package/dist/esm/internal/rateLimiter.js +1 -1
  81. package/dist/esm/internal/rateLimiter.js.map +1 -1
  82. package/dist/esm/internal/stm/core.js +4 -0
  83. package/dist/esm/internal/stm/core.js.map +1 -1
  84. package/dist/esm/internal/stm/stm.js +2 -20
  85. package/dist/esm/internal/stm/stm.js.map +1 -1
  86. package/dist/esm/internal/version.js +1 -1
  87. package/package.json +1 -1
  88. package/src/Cause.ts +1 -0
  89. package/src/Chunk.ts +1 -2
  90. package/src/Effect.ts +46 -41
  91. package/src/Either.ts +5 -7
  92. package/src/Match.ts +97 -109
  93. package/src/Option.ts +5 -7
  94. package/src/Order.ts +15 -0
  95. package/src/STM.ts +25 -36
  96. package/src/Utils.ts +31 -28
  97. package/src/index.ts +15 -0
  98. package/src/internal/core-effect.ts +2 -23
  99. package/src/internal/core.ts +10 -0
  100. package/src/internal/effectable.ts +4 -0
  101. package/src/internal/fiberRuntime.ts +3 -3
  102. package/src/internal/matcher.ts +95 -68
  103. package/src/internal/rateLimiter.ts +1 -1
  104. package/src/internal/stm/core.ts +4 -0
  105. package/src/internal/stm/stm.ts +2 -22
  106. package/src/internal/version.ts +1 -1
package/src/Either.ts CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  import * as Equivalence from "./Equivalence.js"
6
6
  import type { LazyArg } from "./Function.js"
7
- import { constNull, constUndefined, dual, identity } from "./Function.js"
7
+ import { constNull, constUndefined, dual, identity, pipe } from "./Function.js"
8
8
  import type { TypeLambda } from "./HKT.js"
9
9
  import type { Inspectable } from "./Inspectable.js"
10
10
  import * as either from "./internal/either.js"
@@ -14,7 +14,7 @@ import type { Predicate, Refinement } from "./Predicate.js"
14
14
  import { isFunction } from "./Predicate.js"
15
15
  import type { Covariant, MergeRecord, NotFunction } from "./Types.js"
16
16
  import type * as Unify from "./Unify.js"
17
- import * as Gen from "./Utils.js"
17
+ import type * as Gen from "./Utils.js"
18
18
 
19
19
  /**
20
20
  * @category models
@@ -698,26 +698,24 @@ export const all: <const I extends Iterable<Either<any, any>> | Record<string, E
698
698
  */
699
699
  export const flip = <R, L>(self: Either<R, L>): Either<L, R> => isLeft(self) ? right(self.left) : left(self.right)
700
700
 
701
- const adapter = Gen.adapter<EitherTypeLambda>()
702
-
703
701
  /**
704
702
  * @category generators
705
703
  * @since 2.0.0
706
704
  */
707
705
  export const gen: Gen.Gen<EitherTypeLambda, Gen.Adapter<EitherTypeLambda>> = (f) => {
708
- const iterator = f(adapter)
706
+ const iterator = f(pipe)
709
707
  let state: IteratorYieldResult<any> | IteratorReturnResult<any> = iterator.next()
710
708
  if (state.done) {
711
709
  return right(state.value) as any
712
710
  } else {
713
- let current = state.value.value
711
+ let current = state.value
714
712
  if (isLeft(current)) {
715
713
  return current
716
714
  }
717
715
  while (!state.done) {
718
716
  state = iterator.next(current.right)
719
717
  if (!state.done) {
720
- current = state.value.value
718
+ current = state.value
721
719
  if (isLeft(current)) {
722
720
  return current
723
721
  }
package/src/Match.ts CHANGED
@@ -25,21 +25,22 @@ export type MatcherTypeId = typeof MatcherTypeId
25
25
  * @category model
26
26
  * @since 1.0.0
27
27
  */
28
- export type Matcher<Input, Filters, RemainingApplied, Result, Provided> =
29
- | TypeMatcher<Input, Filters, RemainingApplied, Result>
30
- | ValueMatcher<Input, Filters, RemainingApplied, Result, Provided>
28
+ export type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any> =
29
+ | TypeMatcher<Input, Filters, RemainingApplied, Result, Return>
30
+ | ValueMatcher<Input, Filters, RemainingApplied, Result, Provided, Return>
31
31
 
32
32
  /**
33
33
  * @category model
34
34
  * @since 1.0.0
35
35
  */
36
- export interface TypeMatcher<in Input, out Filters, out Remaining, out Result> extends Pipeable {
36
+ export interface TypeMatcher<in Input, out Filters, out Remaining, out Result, out Return = any> extends Pipeable {
37
37
  readonly _tag: "TypeMatcher"
38
38
  readonly [MatcherTypeId]: {
39
39
  readonly _input: Contravariant<Input>
40
40
  readonly _filters: Covariant<Filters>
41
41
  readonly _remaining: Covariant<Remaining>
42
42
  readonly _result: Covariant<Result>
43
+ readonly _return: Covariant<Return>
43
44
  }
44
45
  readonly cases: ReadonlyArray<Case>
45
46
  add<I, R, RA, A>(_case: Case): TypeMatcher<I, R, RA, A>
@@ -49,12 +50,15 @@ export interface TypeMatcher<in Input, out Filters, out Remaining, out Result> e
49
50
  * @category model
50
51
  * @since 1.0.0
51
52
  */
52
- export interface ValueMatcher<in Input, Filters, out Remaining, out Result, Provided> extends Pipeable {
53
+ export interface ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>
54
+ extends Pipeable
55
+ {
53
56
  readonly _tag: "ValueMatcher"
54
57
  readonly [MatcherTypeId]: {
55
58
  readonly _input: Contravariant<Input>
56
59
  readonly _filters: Covariant<Filters>
57
60
  readonly _result: Covariant<Result>
61
+ readonly _return: Covariant<Return>
58
62
  }
59
63
  readonly provided: Provided
60
64
  readonly value: Either.Either<Provided, Remaining>
@@ -130,6 +134,15 @@ export const typeTags: <I>() => <
130
134
  & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never }
131
135
  >(fields: P) => (input: I) => Unify<ReturnType<P[keyof P]>> = internal.typeTags
132
136
 
137
+ /**
138
+ * @category combinators
139
+ * @since 1.0.0
140
+ */
141
+ export const withReturnType: <Ret>() => <I, F, R, A, Pr, _>(
142
+ self: Matcher<I, F, R, A, Pr, _>
143
+ ) => Ret extends ([A] extends [never] ? any : A) ? Matcher<I, F, R, A, Pr, Ret>
144
+ : "withReturnType constraint does not extend Result type" = internal.withReturnType
145
+
133
146
  /**
134
147
  * @category combinators
135
148
  * @since 1.0.0
@@ -137,19 +150,21 @@ export const typeTags: <I>() => <
137
150
  export const when: <
138
151
  R,
139
152
  const P extends Types.PatternPrimitive<R> | Types.PatternBase<R>,
140
- Fn extends (_: Types.WhenMatch<R, P>) => unknown
153
+ Ret,
154
+ Fn extends (_: Types.WhenMatch<R, P>) => Ret
141
155
  >(
142
156
  pattern: P,
143
157
  f: Fn
144
158
  ) => <I, F, A, Pr>(
145
- self: Matcher<I, F, R, A, Pr>
159
+ self: Matcher<I, F, R, A, Pr, Ret>
146
160
  ) => Matcher<
147
161
  I,
148
162
  Types.AddWithout<F, Types.PForExclude<P>>,
149
163
  Types.ApplyFilters<I, Types.AddWithout<F, Types.PForExclude<P>>>,
150
164
  A | ReturnType<Fn>,
151
- Pr
152
- > = internal.when as any
165
+ Pr,
166
+ Ret
167
+ > = internal.when
153
168
 
154
169
  /**
155
170
  * @category combinators
@@ -157,21 +172,21 @@ export const when: <
157
172
  */
158
173
  export const whenOr: <
159
174
  R,
160
- const P extends ReadonlyArray<
161
- Types.PatternPrimitive<R> | Types.PatternBase<R>
162
- >,
163
- Fn extends (_: Types.WhenMatch<R, P[number]>) => unknown
175
+ const P extends ReadonlyArray<Types.PatternPrimitive<R> | Types.PatternBase<R>>,
176
+ Ret,
177
+ Fn extends (_: Types.WhenMatch<R, P[number]>) => Ret
164
178
  >(
165
179
  ...args: [...patterns: P, f: Fn]
166
180
  ) => <I, F, A, Pr>(
167
- self: Matcher<I, F, R, A, Pr>
181
+ self: Matcher<I, F, R, A, Pr, Ret>
168
182
  ) => Matcher<
169
183
  I,
170
184
  Types.AddWithout<F, Types.PForExclude<P[number]>>,
171
185
  Types.ApplyFilters<I, Types.AddWithout<F, Types.PForExclude<P[number]>>>,
172
186
  A | ReturnType<Fn>,
173
- Pr
174
- > = internal.whenOr as any
187
+ Pr,
188
+ Ret
189
+ > = internal.whenOr
175
190
 
176
191
  /**
177
192
  * @category combinators
@@ -179,24 +194,20 @@ export const whenOr: <
179
194
  */
180
195
  export const whenAnd: <
181
196
  R,
182
- const P extends ReadonlyArray<
183
- Types.PatternPrimitive<R> | Types.PatternBase<R>
184
- >,
185
- Fn extends (_: Types.WhenMatch<R, Types.ArrayToIntersection<P>>) => unknown
197
+ const P extends ReadonlyArray<Types.PatternPrimitive<R> | Types.PatternBase<R>>,
198
+ Ret,
199
+ Fn extends (_: Types.WhenMatch<R, UnionToIntersection<P[number]>>) => Ret
186
200
  >(
187
201
  ...args: [...patterns: P, f: Fn]
188
202
  ) => <I, F, A, Pr>(
189
- self: Matcher<I, F, R, A, Pr>
203
+ self: Matcher<I, F, R, A, Pr, Ret>
190
204
  ) => Matcher<
191
205
  I,
192
- Types.AddWithout<F, Types.PForExclude<Types.ArrayToIntersection<P>>>,
193
- Types.ApplyFilters<
194
- I,
195
- Types.AddWithout<F, Types.PForExclude<Types.ArrayToIntersection<P>>>
196
- >,
206
+ Types.AddWithout<F, Types.PForExclude<UnionToIntersection<P[number]>>>,
207
+ Types.ApplyFilters<I, Types.AddWithout<F, Types.PForExclude<UnionToIntersection<P[number]>>>>,
197
208
  A | ReturnType<Fn>,
198
209
  Pr
199
- > = internal.whenAnd as any
210
+ > = internal.whenAnd
200
211
 
201
212
  /**
202
213
  * @category combinators
@@ -204,20 +215,17 @@ export const whenAnd: <
204
215
  */
205
216
  export const discriminator: <D extends string>(
206
217
  field: D
207
- ) => <R, P extends Types.Tags<D, R> & string, B>(
208
- ...pattern: [
209
- first: P,
210
- ...values: Array<P>,
211
- f: (_: Extract<R, Record<D, P>>) => B
212
- ]
218
+ ) => <R, P extends Types.Tags<D, R> & string, Ret, B extends Ret>(
219
+ ...pattern: [first: P, ...values: Array<P>, f: (_: Extract<R, Record<D, P>>) => B]
213
220
  ) => <I, F, A, Pr>(
214
- self: Matcher<I, F, R, A, Pr>
221
+ self: Matcher<I, F, R, A, Pr, Ret>
215
222
  ) => Matcher<
216
223
  I,
217
224
  Types.AddWithout<F, Extract<R, Record<D, P>>>,
218
225
  Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<D, P>>>>,
219
226
  B | A,
220
- Pr
227
+ Pr,
228
+ Ret
221
229
  > = internal.discriminator
222
230
 
223
231
  /**
@@ -226,20 +234,18 @@ export const discriminator: <D extends string>(
226
234
  */
227
235
  export const discriminatorStartsWith: <D extends string>(
228
236
  field: D
229
- ) => <R, P extends string, B>(
237
+ ) => <R, P extends string, Ret, B extends Ret>(
230
238
  pattern: P,
231
239
  f: (_: Extract<R, Record<D, `${P}${string}`>>) => B
232
240
  ) => <I, F, A, Pr>(
233
- self: Matcher<I, F, R, A, Pr>
241
+ self: Matcher<I, F, R, A, Pr, Ret>
234
242
  ) => Matcher<
235
243
  I,
236
244
  Types.AddWithout<F, Extract<R, Record<D, `${P}${string}`>>>,
237
- Types.ApplyFilters<
238
- I,
239
- Types.AddWithout<F, Extract<R, Record<D, `${P}${string}`>>>
240
- >,
245
+ Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<D, `${P}${string}`>>>>,
241
246
  B | A,
242
- Pr
247
+ Pr,
248
+ Ret
243
249
  > = internal.discriminatorStartsWith as any
244
250
 
245
251
  /**
@@ -250,23 +256,21 @@ export const discriminators: <D extends string>(
250
256
  field: D
251
257
  ) => <
252
258
  R,
259
+ Ret,
253
260
  P extends
254
- & {
255
- readonly [Tag in Types.Tags<D, R> & string]?:
256
- | ((_: Extract<R, Record<D, Tag>>) => any)
257
- | undefined
258
- }
261
+ & { readonly [Tag in Types.Tags<D, R> & string]?: ((_: Extract<R, Record<D, Tag>>) => Ret) | undefined }
259
262
  & { readonly [Tag in Exclude<keyof P, Types.Tags<D, R>>]: never }
260
263
  >(
261
264
  fields: P
262
265
  ) => <I, F, A, Pr>(
263
- self: Matcher<I, F, R, A, Pr>
266
+ self: Matcher<I, F, R, A, Pr, Ret>
264
267
  ) => Matcher<
265
268
  I,
266
269
  Types.AddWithout<F, Extract<R, Record<D, keyof P>>>,
267
270
  Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<D, keyof P>>>>,
268
271
  A | ReturnType<P[keyof P] & {}>,
269
- Pr
272
+ Pr,
273
+ Ret
270
274
  > = internal.discriminators
271
275
 
272
276
  /**
@@ -277,58 +281,50 @@ export const discriminatorsExhaustive: <D extends string>(
277
281
  field: D
278
282
  ) => <
279
283
  R,
284
+ Ret,
280
285
  P extends
281
- & {
282
- readonly [Tag in Types.Tags<D, R> & string]: (
283
- _: Extract<R, Record<D, Tag>>
284
- ) => any
285
- }
286
+ & { readonly [Tag in Types.Tags<D, R> & string]: (_: Extract<R, Record<D, Tag>>) => Ret }
286
287
  & { readonly [Tag in Exclude<keyof P, Types.Tags<D, R>>]: never }
287
288
  >(
288
289
  fields: P
289
290
  ) => <I, F, A, Pr>(
290
- self: Matcher<I, F, R, A, Pr>
291
- ) => [Pr] extends [never] ? (u: I) => Unify<A | ReturnType<P[keyof P]>>
292
- : Unify<A | ReturnType<P[keyof P]>> = internal.discriminatorsExhaustive
291
+ self: Matcher<I, F, R, A, Pr, Ret>
292
+ ) => [Pr] extends [never] ? (u: I) => Unify<A | ReturnType<P[keyof P]>> : Unify<A | ReturnType<P[keyof P]>> =
293
+ internal.discriminatorsExhaustive
293
294
 
294
295
  /**
295
296
  * @category combinators
296
297
  * @since 1.0.0
297
298
  */
298
- export const tag: <R, P extends Types.Tags<"_tag", R> & string, B>(
299
- ...pattern: [
300
- first: P,
301
- ...values: Array<P>,
302
- f: (_: Extract<R, Record<"_tag", P>>) => B
303
- ]
299
+ export const tag: <R, P extends Types.Tags<"_tag", R> & string, Ret, B extends Ret>(
300
+ ...pattern: [first: P, ...values: Array<P>, f: (_: Extract<R, Record<"_tag", P>>) => B]
304
301
  ) => <I, F, A, Pr>(
305
- self: Matcher<I, F, R, A, Pr>
302
+ self: Matcher<I, F, R, A, Pr, Ret>
306
303
  ) => Matcher<
307
304
  I,
308
305
  Types.AddWithout<F, Extract<R, Record<"_tag", P>>>,
309
306
  Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<"_tag", P>>>>,
310
307
  B | A,
311
- Pr
308
+ Pr,
309
+ Ret
312
310
  > = internal.tag
313
311
 
314
312
  /**
315
313
  * @category combinators
316
314
  * @since 1.0.0
317
315
  */
318
- export const tagStartsWith: <R, P extends string, B>(
316
+ export const tagStartsWith: <R, P extends string, Ret, B extends Ret>(
319
317
  pattern: P,
320
318
  f: (_: Extract<R, Record<"_tag", `${P}${string}`>>) => B
321
319
  ) => <I, F, A, Pr>(
322
- self: Matcher<I, F, R, A, Pr>
320
+ self: Matcher<I, F, R, A, Pr, Ret>
323
321
  ) => Matcher<
324
322
  I,
325
323
  Types.AddWithout<F, Extract<R, Record<"_tag", `${P}${string}`>>>,
326
- Types.ApplyFilters<
327
- I,
328
- Types.AddWithout<F, Extract<R, Record<"_tag", `${P}${string}`>>>
329
- >,
324
+ Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<"_tag", `${P}${string}`>>>>,
330
325
  B | A,
331
- Pr
326
+ Pr,
327
+ Ret
332
328
  > = internal.tagStartsWith as any
333
329
 
334
330
  /**
@@ -337,26 +333,21 @@ export const tagStartsWith: <R, P extends string, B>(
337
333
  */
338
334
  export const tags: <
339
335
  R,
336
+ Ret,
340
337
  P extends
341
- & {
342
- readonly [Tag in Types.Tags<"_tag", R> & string]?:
343
- | ((_: Extract<R, Record<"_tag", Tag>>) => any)
344
- | undefined
345
- }
338
+ & { readonly [Tag in Types.Tags<"_tag", R> & string]?: ((_: Extract<R, Record<"_tag", Tag>>) => Ret) | undefined }
346
339
  & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", R>>]: never }
347
340
  >(
348
341
  fields: P
349
342
  ) => <I, F, A, Pr>(
350
- self: Matcher<I, F, R, A, Pr>
343
+ self: Matcher<I, F, R, A, Pr, Ret>
351
344
  ) => Matcher<
352
345
  I,
353
346
  Types.AddWithout<F, Extract<R, Record<"_tag", keyof P>>>,
354
- Types.ApplyFilters<
355
- I,
356
- Types.AddWithout<F, Extract<R, Record<"_tag", keyof P>>>
357
- >,
347
+ Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<"_tag", keyof P>>>>,
358
348
  A | ReturnType<P[keyof P] & {}>,
359
- Pr
349
+ Pr,
350
+ Ret
360
351
  > = internal.tags
361
352
 
362
353
  /**
@@ -365,19 +356,16 @@ export const tags: <
365
356
  */
366
357
  export const tagsExhaustive: <
367
358
  R,
359
+ Ret,
368
360
  P extends
369
- & {
370
- readonly [Tag in Types.Tags<"_tag", R> & string]: (
371
- _: Extract<R, Record<"_tag", Tag>>
372
- ) => any
373
- }
361
+ & { readonly [Tag in Types.Tags<"_tag", R> & string]: (_: Extract<R, Record<"_tag", Tag>>) => Ret }
374
362
  & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", R>>]: never }
375
363
  >(
376
364
  fields: P
377
365
  ) => <I, F, A, Pr>(
378
- self: Matcher<I, F, R, A, Pr>
379
- ) => [Pr] extends [never] ? (u: I) => Unify<A | ReturnType<P[keyof P]>>
380
- : Unify<A | ReturnType<P[keyof P]>> = internal.tagsExhaustive
366
+ self: Matcher<I, F, R, A, Pr, Ret>
367
+ ) => [Pr] extends [never] ? (u: I) => Unify<A | ReturnType<P[keyof P]>> : Unify<A | ReturnType<P[keyof P]>> =
368
+ internal.tagsExhaustive
381
369
 
382
370
  /**
383
371
  * @category combinators
@@ -386,19 +374,21 @@ export const tagsExhaustive: <
386
374
  export const not: <
387
375
  R,
388
376
  const P extends Types.PatternPrimitive<R> | Types.PatternBase<R>,
389
- Fn extends (_: Types.NotMatch<R, P>) => unknown
377
+ Ret,
378
+ Fn extends (_: Exclude<R, Types.ExtractMatch<R, Types.PForExclude<P>>>) => Ret
390
379
  >(
391
380
  pattern: P,
392
381
  f: Fn
393
382
  ) => <I, F, A, Pr>(
394
- self: Matcher<I, F, R, A, Pr>
383
+ self: Matcher<I, F, R, A, Pr, Ret>
395
384
  ) => Matcher<
396
385
  I,
397
386
  Types.AddOnly<F, Types.WhenMatch<R, P>>,
398
387
  Types.ApplyFilters<I, Types.AddOnly<F, Types.WhenMatch<R, P>>>,
399
388
  A | ReturnType<Fn>,
400
- Pr
401
- > = internal.not as any
389
+ Pr,
390
+ Ret
391
+ > = internal.not
402
392
 
403
393
  /**
404
394
  * @category predicates
@@ -506,44 +496,42 @@ export const instanceOfUnsafe: <A extends abstract new(...args: any) => any>(
506
496
  * @category conversions
507
497
  * @since 1.0.0
508
498
  */
509
- export const orElse: <RA, B>(
499
+ export const orElse: <RA, Ret, B extends Ret>(
510
500
  f: (b: RA) => B
511
501
  ) => <I, R, A, Pr>(
512
- self: Matcher<I, R, RA, A, Pr>
502
+ self: Matcher<I, R, RA, A, Pr, Ret>
513
503
  ) => [Pr] extends [never] ? (input: I) => Unify<B | A> : Unify<B | A> = internal.orElse
514
504
 
515
505
  /**
516
506
  * @category conversions
517
507
  * @since 1.0.0
518
508
  */
519
- export const orElseAbsurd: <I, R, RA, A, Pr>(
520
- self: Matcher<I, R, RA, A, Pr>
509
+ export const orElseAbsurd: <I, R, RA, A, Pr, Ret>(
510
+ self: Matcher<I, R, RA, A, Pr, Ret>
521
511
  ) => [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A> = internal.orElseAbsurd
522
512
 
523
513
  /**
524
514
  * @category conversions
525
515
  * @since 1.0.0
526
516
  */
527
- export const either: <I, F, R, A, Pr>(
528
- self: Matcher<I, F, R, A, Pr>
529
- ) => [Pr] extends [never] ? (input: I) => Either.Either<Unify<A>, R>
530
- : Either.Either<Unify<A>, R> = internal.either
517
+ export const either: <I, F, R, A, Pr, Ret>(
518
+ self: Matcher<I, F, R, A, Pr, Ret>
519
+ ) => [Pr] extends [never] ? (input: I) => Either.Either<Unify<A>, R> : Either.Either<Unify<A>, R> = internal.either
531
520
 
532
521
  /**
533
522
  * @category conversions
534
523
  * @since 1.0.0
535
524
  */
536
- export const option: <I, F, R, A, Pr>(
537
- self: Matcher<I, F, R, A, Pr>
538
- ) => [Pr] extends [never] ? (input: I) => Option.Option<Unify<A>>
539
- : Option.Option<Unify<A>> = internal.option
525
+ export const option: <I, F, R, A, Pr, Ret>(
526
+ self: Matcher<I, F, R, A, Pr, Ret>
527
+ ) => [Pr] extends [never] ? (input: I) => Option.Option<Unify<A>> : Option.Option<Unify<A>> = internal.option
540
528
 
541
529
  /**
542
530
  * @category conversions
543
531
  * @since 1.0.0
544
532
  */
545
- export const exhaustive: <I, F, A, Pr>(
546
- self: Matcher<I, F, never, A, Pr>
533
+ export const exhaustive: <I, F, A, Pr, Ret>(
534
+ self: Matcher<I, F, never, A, Pr, Ret>
547
535
  ) => [Pr] extends [never] ? (u: I) => Unify<A> : Unify<A> = internal.exhaustive
548
536
 
549
537
  /**
package/src/Option.ts CHANGED
@@ -5,7 +5,7 @@ import type { Either } from "./Either.js"
5
5
  import * as Equal from "./Equal.js"
6
6
  import * as Equivalence from "./Equivalence.js"
7
7
  import type { LazyArg } from "./Function.js"
8
- import { constNull, constUndefined, dual, identity, isFunction } from "./Function.js"
8
+ import { constNull, constUndefined, dual, identity, isFunction, pipe } from "./Function.js"
9
9
  import type { TypeLambda } from "./HKT.js"
10
10
  import type { Inspectable } from "./Inspectable.js"
11
11
  import * as either from "./internal/either.js"
@@ -16,7 +16,7 @@ import type { Pipeable } from "./Pipeable.js"
16
16
  import type { Predicate, Refinement } from "./Predicate.js"
17
17
  import type { Covariant, NotFunction } from "./Types.js"
18
18
  import type * as Unify from "./Unify.js"
19
- import * as Gen from "./Utils.js"
19
+ import type * as Gen from "./Utils.js"
20
20
 
21
21
  /**
22
22
  * @category models
@@ -1261,26 +1261,24 @@ export const bind: {
1261
1261
  */
1262
1262
  export const Do: Option<{}> = some({})
1263
1263
 
1264
- const adapter = Gen.adapter<OptionTypeLambda>()
1265
-
1266
1264
  /**
1267
1265
  * @category generators
1268
1266
  * @since 2.0.0
1269
1267
  */
1270
1268
  export const gen: Gen.Gen<OptionTypeLambda, Gen.Adapter<OptionTypeLambda>> = (f) => {
1271
- const iterator = f(adapter)
1269
+ const iterator = f(pipe)
1272
1270
  let state: IteratorYieldResult<any> | IteratorReturnResult<any> = iterator.next()
1273
1271
  if (state.done) {
1274
1272
  return some(state.value)
1275
1273
  } else {
1276
- let current = state.value.value
1274
+ let current = state.value
1277
1275
  if (isNone(current)) {
1278
1276
  return current
1279
1277
  }
1280
1278
  while (!state.done) {
1281
1279
  state = iterator.next(current.value)
1282
1280
  if (!state.done) {
1283
- current = state.value.value
1281
+ current = state.value
1284
1282
  if (isNone(current)) {
1285
1283
  return current
1286
1284
  }
package/src/Order.ts CHANGED
@@ -1,4 +1,19 @@
1
1
  /**
2
+ * This module provides an implementation of the `Order` type class which is used to define a total ordering on some type `A`.
3
+ * An order is defined by a relation `<=`, which obeys the following laws:
4
+ *
5
+ * - either `x <= y` or `y <= x` (totality)
6
+ * - if `x <= y` and `y <= x`, then `x == y` (antisymmetry)
7
+ * - if `x <= y` and `y <= z`, then `x <= z` (transitivity)
8
+ *
9
+ * The truth table for compare is defined as follows:
10
+ *
11
+ * | `x <= y` | `x >= y` | Ordering | |
12
+ * | -------- | -------- | -------- | --------------------- |
13
+ * | `true` | `true` | `0` | corresponds to x == y |
14
+ * | `true` | `false` | `< 0` | corresponds to x < y |
15
+ * | `false` | `true` | `> 0` | corresponds to x > y |
16
+ *
2
17
  * @since 2.0.0
3
18
  */
4
19
  import { dual } from "./Function.js"