effect 3.4.2 → 3.4.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 (105) hide show
  1. package/dist/cjs/Micro.js +42 -16
  2. package/dist/cjs/Micro.js.map +1 -1
  3. package/dist/cjs/internal/version.js +1 -1
  4. package/dist/dts/Array.d.ts +15 -15
  5. package/dist/dts/Array.d.ts.map +1 -1
  6. package/dist/dts/BigDecimal.d.ts.map +1 -1
  7. package/dist/dts/BigInt.d.ts.map +1 -1
  8. package/dist/dts/Boolean.d.ts.map +1 -1
  9. package/dist/dts/Brand.d.ts.map +1 -1
  10. package/dist/dts/Chunk.d.ts +3 -2
  11. package/dist/dts/Chunk.d.ts.map +1 -1
  12. package/dist/dts/Cron.d.ts.map +1 -1
  13. package/dist/dts/Data.d.ts +3 -3
  14. package/dist/dts/Data.d.ts.map +1 -1
  15. package/dist/dts/Duration.d.ts.map +1 -1
  16. package/dist/dts/Effect.d.ts.map +1 -1
  17. package/dist/dts/Either.d.ts.map +1 -1
  18. package/dist/dts/Encoding.d.ts.map +1 -1
  19. package/dist/dts/Equal.d.ts.map +1 -1
  20. package/dist/dts/Equivalence.d.ts +1 -1
  21. package/dist/dts/Equivalence.d.ts.map +1 -1
  22. package/dist/dts/FiberHandle.d.ts +1 -1
  23. package/dist/dts/FiberHandle.d.ts.map +1 -1
  24. package/dist/dts/FiberMap.d.ts +1 -1
  25. package/dist/dts/FiberMap.d.ts.map +1 -1
  26. package/dist/dts/FiberSet.d.ts.map +1 -1
  27. package/dist/dts/Function.d.ts +3 -3
  28. package/dist/dts/Function.d.ts.map +1 -1
  29. package/dist/dts/GlobalValue.d.ts.map +1 -1
  30. package/dist/dts/Hash.d.ts.map +1 -1
  31. package/dist/dts/HashMap.d.ts.map +1 -1
  32. package/dist/dts/Iterable.d.ts.map +1 -1
  33. package/dist/dts/List.d.ts +1 -1
  34. package/dist/dts/List.d.ts.map +1 -1
  35. package/dist/dts/Micro.d.ts +62 -10
  36. package/dist/dts/Micro.d.ts.map +1 -1
  37. package/dist/dts/MutableHashMap.d.ts.map +1 -1
  38. package/dist/dts/MutableHashSet.d.ts +1 -1
  39. package/dist/dts/MutableHashSet.d.ts.map +1 -1
  40. package/dist/dts/MutableList.d.ts.map +1 -1
  41. package/dist/dts/MutableQueue.d.ts.map +1 -1
  42. package/dist/dts/MutableRef.d.ts.map +1 -1
  43. package/dist/dts/NonEmptyIterable.d.ts.map +1 -1
  44. package/dist/dts/Number.d.ts.map +1 -1
  45. package/dist/dts/Option.d.ts +2 -2
  46. package/dist/dts/Option.d.ts.map +1 -1
  47. package/dist/dts/Order.d.ts +1 -1
  48. package/dist/dts/Order.d.ts.map +1 -1
  49. package/dist/dts/Ordering.d.ts.map +1 -1
  50. package/dist/dts/Pipeable.d.ts.map +1 -1
  51. package/dist/dts/Predicate.d.ts +2 -3
  52. package/dist/dts/Predicate.d.ts.map +1 -1
  53. package/dist/dts/Readable.d.ts.map +1 -1
  54. package/dist/dts/Record.d.ts +1 -1
  55. package/dist/dts/Record.d.ts.map +1 -1
  56. package/dist/dts/Redacted.d.ts.map +1 -1
  57. package/dist/dts/Request.d.ts.map +1 -1
  58. package/dist/dts/RequestResolver.d.ts +1 -1
  59. package/dist/dts/RequestResolver.d.ts.map +1 -1
  60. package/dist/dts/STM.d.ts.map +1 -1
  61. package/dist/dts/Scheduler.d.ts.map +1 -1
  62. package/dist/dts/SortedMap.d.ts +1 -1
  63. package/dist/dts/SortedMap.d.ts.map +1 -1
  64. package/dist/dts/SortedSet.d.ts +1 -1
  65. package/dist/dts/SortedSet.d.ts.map +1 -1
  66. package/dist/dts/Streamable.d.ts.map +1 -1
  67. package/dist/dts/String.d.ts.map +1 -1
  68. package/dist/dts/Struct.d.ts.map +1 -1
  69. package/dist/dts/Subscribable.d.ts.map +1 -1
  70. package/dist/dts/TestAnnotation.d.ts.map +1 -1
  71. package/dist/dts/TestAnnotationMap.d.ts +4 -4
  72. package/dist/dts/TestAnnotationMap.d.ts.map +1 -1
  73. package/dist/dts/TestAnnotations.d.ts.map +1 -1
  74. package/dist/dts/TestClock.d.ts +1 -1
  75. package/dist/dts/TestClock.d.ts.map +1 -1
  76. package/dist/dts/TestLive.d.ts.map +1 -1
  77. package/dist/dts/TestServices.d.ts +6 -6
  78. package/dist/dts/TestServices.d.ts.map +1 -1
  79. package/dist/dts/TestSized.d.ts.map +1 -1
  80. package/dist/dts/Trie.d.ts.map +1 -1
  81. package/dist/dts/Tuple.d.ts +1 -1
  82. package/dist/dts/Tuple.d.ts.map +1 -1
  83. package/dist/dts/Utils.d.ts.map +1 -1
  84. package/dist/dts/internal/core-effect.d.ts +1 -1
  85. package/dist/dts/internal/core-effect.d.ts.map +1 -1
  86. package/dist/dts/internal/core-stream.d.ts.map +1 -1
  87. package/dist/dts/internal/hashMap.d.ts +1 -1
  88. package/dist/dts/internal/hashMap.d.ts.map +1 -1
  89. package/dist/dts/internal/layer.d.ts +6 -6
  90. package/dist/dts/internal/layer.d.ts.map +1 -1
  91. package/dist/dts/internal/metric/keyType.d.ts.map +1 -1
  92. package/dist/dts/internal/metric/state.d.ts.map +1 -1
  93. package/dist/dts/internal/random.d.ts.map +1 -1
  94. package/dist/dts/internal/runtimeFlags.d.ts.map +1 -1
  95. package/dist/dts/internal/stack.d.ts.map +1 -1
  96. package/dist/dts/internal/stm/stm.d.ts +1 -1
  97. package/dist/dts/internal/stm/stm.d.ts.map +1 -1
  98. package/dist/dts/internal/stream.d.ts +1 -1
  99. package/dist/dts/internal/stream.d.ts.map +1 -1
  100. package/dist/esm/Micro.js +39 -14
  101. package/dist/esm/Micro.js.map +1 -1
  102. package/dist/esm/internal/version.js +1 -1
  103. package/package.json +1 -1
  104. package/src/Micro.ts +102 -42
  105. package/src/internal/version.ts +1 -1
package/src/Micro.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import type { Channel, ChannelTypeId } from "./Channel.js"
8
8
  import * as Context from "./Context.js"
9
- import type { Effect, EffectTypeId } from "./Effect.js"
9
+ import type { Effect, EffectTypeId, EffectUnify, EffectUnifyIgnore } from "./Effect.js"
10
10
  import * as Effectable from "./Effectable.js"
11
11
  import * as Either from "./Either.js"
12
12
  import { constTrue, constVoid, dual, identity, type LazyArg } from "./Function.js"
@@ -24,6 +24,7 @@ import type { ReadonlyRecord } from "./Record.js"
24
24
  import type { Sink, SinkTypeId } from "./Sink.js"
25
25
  import type { Stream, StreamTypeId } from "./Stream.js"
26
26
  import type { Concurrency, Covariant, Equals, NoInfer, NotFunction, Simplify } from "./Types.js"
27
+ import type * as Unify from "./Unify.js"
27
28
  import { YieldWrap, yieldWrapGet } from "./Utils.js"
28
29
 
29
30
  /**
@@ -64,9 +65,27 @@ export type runSymbol = typeof runSymbol
64
65
  export interface Micro<out A, out E = never, out R = never> extends Effect<A, E, R> {
65
66
  readonly [TypeId]: Micro.Variance<A, E, R>
66
67
  readonly [runSymbol]: (env: Env<any>, onResult: (result: Result<A, E>) => void) => void
68
+ [Unify.typeSymbol]?: unknown
69
+ [Unify.unifySymbol]?: MicroUnify<this>
70
+ [Unify.ignoreSymbol]?: MicroUnifyIgnore
67
71
  [Symbol.iterator](): MicroIterator<Micro<A, E, R>>
68
72
  }
69
73
 
74
+ /**
75
+ * @category models
76
+ * @since 3.4.3
77
+ */
78
+ export interface MicroUnify<A extends { [Unify.typeSymbol]?: any }> extends EffectUnify<A> {
79
+ Micro?: () => A[Unify.typeSymbol] extends Micro<infer A0, infer E0, infer R0> | infer _ ? Micro<A0, E0, R0> : never
80
+ }
81
+
82
+ /**
83
+ * @category models
84
+ * @since 3.4.3
85
+ */
86
+ export interface MicroUnifyIgnore extends EffectUnifyIgnore {
87
+ Effect?: true
88
+ }
70
89
  /**
71
90
  * @category type lambdas
72
91
  * @since 3.4.1
@@ -713,7 +732,7 @@ export const envRefMake = <A>(key: string, initial: LazyArg<A>): EnvRef<A> =>
713
732
  */
714
733
  export const currentAbortController: EnvRef<AbortController> = envRefMake(
715
734
  "effect/Micro/currentAbortController",
716
- () => new AbortController()
735
+ () => undefined as any
717
736
  )
718
737
 
719
738
  /**
@@ -723,7 +742,7 @@ export const currentAbortController: EnvRef<AbortController> = envRefMake(
723
742
  */
724
743
  export const currentAbortSignal: EnvRef<AbortSignal> = envRefMake(
725
744
  "effect/Micro/currentAbortSignal",
726
- () => currentAbortController.initial.signal
745
+ () => undefined as any
727
746
  )
728
747
 
729
748
  /**
@@ -981,17 +1000,17 @@ export const sync = <A>(evaluate: LazyArg<A>): Micro<A> =>
981
1000
  })
982
1001
 
983
1002
  /**
984
- * Converts an `Option` into a `Micro` effect, that will fail with a
985
- * `Option.None` if the option is `None`. Otherwise, it will succeed with the
1003
+ * Converts an `Option` into a `Micro` effect, that will fail with
1004
+ * `NoSuchElementException` if the option is `None`. Otherwise, it will succeed with the
986
1005
  * value of the option.
987
1006
  *
988
1007
  * @since 3.4.0
989
1008
  * @experimental
990
1009
  * @category constructors
991
1010
  */
992
- export const fromOption = <A>(option: Option.Option<A>): Micro<A, Option.None<never>> =>
1011
+ export const fromOption = <A>(option: Option.Option<A>): Micro<A, NoSuchElementException> =>
993
1012
  make(function(_env, onResult) {
994
- onResult(option._tag === "Some" ? ResultSuccess(option.value) : ResultFail(Option.none()) as any)
1013
+ onResult(option._tag === "Some" ? ResultSuccess(option.value) : ResultFail(new NoSuchElementException({})))
995
1014
  })
996
1015
 
997
1016
  /**
@@ -1224,15 +1243,17 @@ export const never: Micro<never> = async<never>(function() {
1224
1243
  * @experimental
1225
1244
  * @category constructors
1226
1245
  */
1227
- export const gen = <Eff extends YieldWrap<Micro<any, any, any>>, AEff>(
1228
- f: () => Generator<Eff, AEff, never>
1246
+ export const gen = <Self, Eff extends YieldWrap<Micro<any, any, any>>, AEff>(
1247
+ ...args:
1248
+ | [self: Self, body: (this: Self) => Generator<Eff, AEff, never>]
1249
+ | [body: () => Generator<Eff, AEff, never>]
1229
1250
  ): Micro<
1230
1251
  AEff,
1231
1252
  [Eff] extends [never] ? never : [Eff] extends [YieldWrap<Micro<infer _A, infer E, infer _R>>] ? E : never,
1232
1253
  [Eff] extends [never] ? never : [Eff] extends [YieldWrap<Micro<infer _A, infer _E, infer R>>] ? R : never
1233
1254
  > =>
1234
1255
  make(function(env, onResult) {
1235
- const iterator = f() as Iterator<YieldWrap<Micro<any, any, any>>, AEff, any>
1256
+ const iterator: Generator<Eff, AEff, any> = args.length === 1 ? args[0]() : args[1].call(args[0])
1236
1257
  let running = false
1237
1258
  let value: any = undefined
1238
1259
  function run() {
@@ -1653,21 +1674,46 @@ export const zip: {
1653
1674
  <A, E, R, A2, E2, R2>(
1654
1675
  self: Micro<A, E, R>,
1655
1676
  that: Micro<A2, E2, R2>,
1656
- options?:
1657
- | { readonly concurrent?: boolean | undefined }
1658
- | undefined
1677
+ options?: { readonly concurrent?: boolean | undefined }
1659
1678
  ): Micro<[A, A2], E | E2, R | R2>
1660
1679
  } = dual((args) => isMicro(args[1]), <A, E, R, A2, E2, R2>(
1661
1680
  self: Micro<A, E, R>,
1662
1681
  that: Micro<A2, E2, R2>,
1663
- options?:
1664
- | { readonly concurrent?: boolean | undefined }
1665
- | undefined
1666
- ): Micro<[A, A2], E | E2, R | R2> => {
1682
+ options?: { readonly concurrent?: boolean | undefined }
1683
+ ): Micro<[A, A2], E | E2, R | R2> => zipWith(self, that, (a, a2) => [a, a2], options))
1684
+
1685
+ /**
1686
+ * The `Micro.zipWith` function combines two `Micro` effects and allows you to
1687
+ * apply a function to the results of the combined effects, transforming them
1688
+ * into a single value.
1689
+ *
1690
+ * @since 3.4.3
1691
+ * @experimental
1692
+ * @category zipping
1693
+ */
1694
+ export const zipWith: {
1695
+ <A2, E2, R2, A, B>(
1696
+ that: Micro<A2, E2, R2>,
1697
+ f: (a: A, b: A2) => B,
1698
+ options?: { readonly concurrent?: boolean | undefined }
1699
+ ): <E, R>(self: Micro<A, E, R>) => Micro<B, E2 | E, R2 | R>
1700
+ <A, E, R, A2, E2, R2, B>(
1701
+ self: Micro<A, E, R>,
1702
+ that: Micro<A2, E2, R2>,
1703
+ f: (a: A, b: A2) => B,
1704
+ options?: { readonly concurrent?: boolean | undefined }
1705
+ ): Micro<B, E2 | E, R2 | R>
1706
+ } = dual((args) => isMicro(args[1]), <A, E, R, A2, E2, R2, B>(
1707
+ self: Micro<A, E, R>,
1708
+ that: Micro<A2, E2, R2>,
1709
+ f: (a: A, b: A2) => B,
1710
+ options?: { readonly concurrent?: boolean | undefined }
1711
+ ): Micro<B, E2 | E, R2 | R> => {
1667
1712
  if (options?.concurrent) {
1668
- return all([self, that], { concurrency: "unbounded" })
1713
+ // Use `all` exclusively for concurrent cases, as it introduces additional overhead due to the management of concurrency
1714
+ return map(all([self, that], { concurrency: "unbounded" }), ([a, a2]) => f(a, a2))
1669
1715
  }
1670
- return flatMap(self, (a) => map(that, (a2) => [a, a2]))
1716
+ return flatMap(self, (a) => map(that, (a2) => f(a, a2)))
1671
1717
  })
1672
1718
 
1673
1719
  // ----------------------------------------------------------------------------
@@ -2162,34 +2208,34 @@ export const tapUnexpected: {
2162
2208
  * @category error handling
2163
2209
  */
2164
2210
  export const catchIf: {
2165
- <E, EB extends E, B, E2, R2>(
2166
- pred: Refinement<E, EB>,
2167
- f: (a: NoInfer<EB>) => Micro<B, E2, R2>
2168
- ): <A, R>(self: Micro<A, E, R>) => Micro<A | B, E2, R | R2>
2169
- <E, B, E2, R2>(
2170
- pred: Predicate<NoInfer<E>>,
2171
- f: (a: NoInfer<E>) => Micro<B, E2, R2>
2172
- ): <A, R>(self: Micro<A, E, R>) => Micro<A | B, E2, R | R2>
2173
- <A, E, R, EB extends E, B, E2, R2>(
2211
+ <E, EB extends E, A2, E2, R2>(
2212
+ refinement: Refinement<NoInfer<E>, EB>,
2213
+ f: (e: EB) => Micro<A2, E2, R2>
2214
+ ): <A, R>(self: Micro<A, E, R>) => Micro<A2 | A, E2 | Exclude<E, EB>, R2 | R>
2215
+ <E, A2, E2, R2>(
2216
+ predicate: Predicate<NoInfer<E>>,
2217
+ f: (e: NoInfer<E>) => Micro<A2, E2, R2>
2218
+ ): <A, R>(self: Micro<A, E, R>) => Micro<A2 | A, E | E2, R2 | R>
2219
+ <A, E, R, EB extends E, A2, E2, R2>(
2174
2220
  self: Micro<A, E, R>,
2175
- pred: Refinement<E, EB>,
2176
- f: (a: NoInfer<EB>) => Micro<B, E2, R2>
2177
- ): Micro<A | B, E2, R | R2>
2178
- <A, E, R, B, E2, R2>(
2221
+ refinement: Refinement<E, EB>,
2222
+ f: (e: EB) => Micro<A2, E2, R2>
2223
+ ): Micro<A | A2, E2 | Exclude<E, EB>, R | R2>
2224
+ <A, E, R, A2, E2, R2>(
2179
2225
  self: Micro<A, E, R>,
2180
- pred: Predicate<NoInfer<E>>,
2181
- f: (a: NoInfer<E>) => Micro<B, E2, R2>
2182
- ): Micro<A | B, E2, R | R2>
2226
+ predicate: Predicate<E>,
2227
+ f: (e: E) => Micro<A2, E2, R2>
2228
+ ): Micro<A | A2, E | E2, R | R2>
2183
2229
  } = dual(
2184
2230
  3,
2185
- <A, E, R, EB extends E, B, E2, R2>(
2231
+ <A, E, R, A2, E2, R2>(
2186
2232
  self: Micro<A, E, R>,
2187
- pred: Refinement<E, EB>,
2188
- f: (a: NoInfer<EB>) => Micro<B, E2, R2>
2189
- ): Micro<A | B, E2, R | R2> =>
2233
+ predicate: Predicate<E>,
2234
+ f: (e: E) => Micro<A2, E2, R2>
2235
+ ): Micro<A | A2, E | E2, R | R2> =>
2190
2236
  catchFailureIf(
2191
2237
  self,
2192
- (f): f is Failure.Expected<EB> => failureIsExpected(f) && pred(f.error),
2238
+ (f): f is Failure.Expected<E> => failureIsExpected(f) && predicate(f.error),
2193
2239
  (failure) => f(failure.error)
2194
2240
  )
2195
2241
  )
@@ -2215,7 +2261,8 @@ export const catchTag: {
2215
2261
  self: Micro<A, E, R>,
2216
2262
  k: K,
2217
2263
  f: (e: Extract<E, { _tag: K }>) => Micro<A1, E1, R1>
2218
- ): Micro<A | A1, E1 | Exclude<E, { _tag: K }>, R | R1> => catchIf(self, (error) => isTagged(error, k), f as any))
2264
+ ): Micro<A | A1, E1 | Exclude<E, { _tag: K }>, R | R1> =>
2265
+ catchIf(self, isTagged(k) as Refinement<E, Extract<E, { _tag: K }>>, f) as any)
2219
2266
 
2220
2267
  /**
2221
2268
  * Transform the full `Failure` object of the given `Micro` effect.
@@ -3650,12 +3697,15 @@ export const runFork = <A, E>(
3650
3697
  const handle = new HandleImpl<A, E>(controller.signal, controller)
3651
3698
  effect[runSymbol](envSet(env, currentAbortSignal, handle._controller.signal), (result) => {
3652
3699
  handle.emit(result)
3700
+ if (options?.signal) {
3701
+ options.signal.removeEventListener("abort", handle.unsafeAbort)
3702
+ }
3653
3703
  })
3654
3704
  if (options?.signal) {
3655
3705
  if (options.signal.aborted) {
3656
3706
  handle.unsafeAbort()
3657
3707
  } else {
3658
- options.signal.addEventListener("abort", () => handle.unsafeAbort())
3708
+ options.signal.addEventListener("abort", handle.unsafeAbort, { once: true })
3659
3709
  }
3660
3710
  }
3661
3711
  return handle
@@ -3815,3 +3865,13 @@ export const TaggedError = <Tag extends string>(tag: Tag): new<A extends Record<
3815
3865
  ;(Base.prototype as any).name = tag
3816
3866
  return Base as any
3817
3867
  }
3868
+
3869
+ /**
3870
+ * Represents a checked exception which occurs when an expected element was
3871
+ * unable to be found.
3872
+ *
3873
+ * @since 3.4.4
3874
+ * @experimental
3875
+ * @category errors
3876
+ */
3877
+ export class NoSuchElementException extends TaggedError("NoSuchElementException")<{ message?: string | undefined }> {}
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.4.2"
1
+ let moduleVersion = "3.4.4"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4