effect 2.3.1 → 2.3.2

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 (50) hide show
  1. package/dist/cjs/Effect.js.map +1 -1
  2. package/dist/cjs/Either.js +4 -1
  3. package/dist/cjs/Either.js.map +1 -1
  4. package/dist/cjs/Option.js +4 -1
  5. package/dist/cjs/Option.js.map +1 -1
  6. package/dist/cjs/Scheduler.js +3 -4
  7. package/dist/cjs/Scheduler.js.map +1 -1
  8. package/dist/cjs/internal/clock.js +2 -3
  9. package/dist/cjs/internal/clock.js.map +1 -1
  10. package/dist/cjs/internal/fiberRuntime.js +12 -2
  11. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  12. package/dist/cjs/internal/version.js +1 -1
  13. package/dist/dts/Effect.d.ts +1 -1
  14. package/dist/dts/Effect.d.ts.map +1 -1
  15. package/dist/dts/Either.d.ts +4 -0
  16. package/dist/dts/Either.d.ts.map +1 -1
  17. package/dist/dts/FiberSet.d.ts +4 -4
  18. package/dist/dts/FiberSet.d.ts.map +1 -1
  19. package/dist/dts/Option.d.ts +4 -0
  20. package/dist/dts/Option.d.ts.map +1 -1
  21. package/dist/dts/Scheduler.d.ts.map +1 -1
  22. package/dist/dts/internal/version.d.ts +1 -1
  23. package/dist/esm/Effect.js.map +1 -1
  24. package/dist/esm/Either.js +4 -1
  25. package/dist/esm/Either.js.map +1 -1
  26. package/dist/esm/Option.js +4 -1
  27. package/dist/esm/Option.js.map +1 -1
  28. package/dist/esm/Scheduler.js +3 -4
  29. package/dist/esm/Scheduler.js.map +1 -1
  30. package/dist/esm/internal/clock.js +2 -3
  31. package/dist/esm/internal/clock.js.map +1 -1
  32. package/dist/esm/internal/fiberRuntime.js +12 -2
  33. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  34. package/dist/esm/internal/version.js +1 -1
  35. package/package.json +1 -1
  36. package/src/Effect.ts +1 -1
  37. package/src/Either.ts +8 -1
  38. package/src/FiberSet.ts +4 -4
  39. package/src/Option.ts +8 -1
  40. package/src/Scheduler.ts +3 -4
  41. package/src/internal/clock.ts +2 -3
  42. package/src/internal/fiberRuntime.ts +13 -3
  43. package/src/internal/version.ts +1 -1
  44. package/dist/cjs/internal/timeout.js +0 -24
  45. package/dist/cjs/internal/timeout.js.map +0 -1
  46. package/dist/dts/internal/timeout.d.ts +0 -7
  47. package/dist/dts/internal/timeout.d.ts.map +0 -1
  48. package/dist/esm/internal/timeout.js +0 -18
  49. package/dist/esm/internal/timeout.js.map +0 -1
  50. package/src/internal/timeout.ts +0 -23
package/src/FiberSet.ts CHANGED
@@ -26,7 +26,7 @@ export type TypeId = typeof TypeId
26
26
  * @since 2.0.0
27
27
  * @categories models
28
28
  */
29
- export interface FiberSet<out A, out E = never>
29
+ export interface FiberSet<out A = unknown, out E = unknown>
30
30
  extends Pipeable, Inspectable.Inspectable, Iterable<Fiber.RuntimeFiber<A, E>>
31
31
  {
32
32
  readonly [TypeId]: TypeId
@@ -92,7 +92,7 @@ const unsafeMake = <A, E>(): FiberSet<A, E> => {
92
92
  * @since 2.0.0
93
93
  * @categories constructors
94
94
  */
95
- export const make = <A, E = never>(): Effect.Effect<FiberSet<A, E>, never, Scope.Scope> =>
95
+ export const make = <A = unknown, E = unknown>(): Effect.Effect<FiberSet<A, E>, never, Scope.Scope> =>
96
96
  Effect.acquireRelease(Effect.sync(() => unsafeMake<A, E>()), clear)
97
97
 
98
98
  /**
@@ -101,7 +101,7 @@ export const make = <A, E = never>(): Effect.Effect<FiberSet<A, E>, never, Scope
101
101
  * @since 2.0.0
102
102
  * @categories constructors
103
103
  */
104
- export const makeRuntime = <A, E = never, R = never>(): Effect.Effect<
104
+ export const makeRuntime = <R = never, A = unknown, E = unknown>(): Effect.Effect<
105
105
  <XE extends E, XA extends A>(
106
106
  effect: Effect.Effect<XA, XE, R>,
107
107
  options?: Runtime.RunForkOptions | undefined
@@ -234,7 +234,7 @@ export const run: {
234
234
  * @since 2.0.0
235
235
  * @categories combinators
236
236
  */
237
- export const runtime: <A, E = never>(
237
+ export const runtime: <A, E>(
238
238
  self: FiberSet<A, E>
239
239
  ) => <R = never>() => Effect.Effect<
240
240
  <XE extends E, XA extends A>(
package/src/Option.ts CHANGED
@@ -648,12 +648,19 @@ export const flatMap: {
648
648
  export const andThen: {
649
649
  <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>
650
650
  <B>(f: Option<B>): <A>(self: Option<A>) => Option<B>
651
+ <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>
652
+ <B>(f: B): <A>(self: Option<A>) => Option<B>
651
653
  <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>
652
654
  <A, B>(self: Option<A>, f: Option<B>): Option<B>
655
+ <A, B>(self: Option<A>, f: (a: A) => B): Option<B>
656
+ <A, B>(self: Option<A>, f: B): Option<B>
653
657
  } = dual(
654
658
  2,
655
659
  <A, B>(self: Option<A>, f: (a: A) => Option<B> | Option<B>): Option<B> =>
656
- isFunction(f) ? flatMap(self, f) : flatMap(self, () => f)
660
+ flatMap(self, (a) => {
661
+ const b = isFunction(f) ? f(a) : f
662
+ return isOption(b) ? b : some(b)
663
+ })
657
664
  )
658
665
 
659
666
  /**
package/src/Scheduler.ts CHANGED
@@ -8,7 +8,6 @@ import type { FiberRef } from "./FiberRef.js"
8
8
  import { dual } from "./Function.js"
9
9
  import { globalValue } from "./GlobalValue.js"
10
10
  import * as core from "./internal/core.js"
11
- import * as timeout from "./internal/timeout.js"
12
11
 
13
12
  /**
14
13
  * @since 2.0.0
@@ -107,7 +106,7 @@ export class MixedScheduler implements Scheduler {
107
106
  */
108
107
  private starve(depth = 0) {
109
108
  if (depth >= this.maxNextTickBeforeTimer) {
110
- timeout.set(() => this.starveInternal(0), 0)
109
+ setTimeout(() => this.starveInternal(0), 0)
111
110
  } else {
112
111
  Promise.resolve(void 0).then(() => this.starveInternal(depth + 1))
113
112
  }
@@ -337,14 +336,14 @@ export const makeBatched = (
337
336
  * @category constructors
338
337
  */
339
338
  export const timer = (ms: number, shouldYield: Scheduler["shouldYield"] = defaultShouldYield) =>
340
- make((task) => timeout.set(task, ms), shouldYield)
339
+ make((task) => setTimeout(task, ms), shouldYield)
341
340
 
342
341
  /**
343
342
  * @since 2.0.0
344
343
  * @category constructors
345
344
  */
346
345
  export const timerBatched = (ms: number, shouldYield: Scheduler["shouldYield"] = defaultShouldYield) =>
347
- makeBatched((task) => timeout.set(task, ms), shouldYield)
346
+ makeBatched((task) => setTimeout(task, ms), shouldYield)
348
347
 
349
348
  /** @internal */
350
349
  export const currentScheduler: FiberRef<Scheduler> = globalValue(
@@ -5,7 +5,6 @@ import type * as Effect from "../Effect.js"
5
5
  import * as Either from "../Either.js"
6
6
  import { constFalse } from "../Function.js"
7
7
  import * as core from "./core.js"
8
- import * as timeout from "./timeout.js"
9
8
 
10
9
  /** @internal */
11
10
  const ClockSymbolKey = "effect/Clock"
@@ -29,12 +28,12 @@ export const globalClockScheduler: Clock.ClockScheduler = {
29
28
  return constFalse
30
29
  }
31
30
  let completed = false
32
- const handle = timeout.set(() => {
31
+ const handle = setTimeout(() => {
33
32
  completed = true
34
33
  task()
35
34
  }, millis)
36
35
  return () => {
37
- timeout.clear(handle)
36
+ clearTimeout(handle)
38
37
  return !completed
39
38
  }
40
39
  }
@@ -2771,7 +2771,12 @@ export const zipLeftOptions = dual<
2771
2771
  ) => Effect.Effect<A, E | E2, R | R2>
2772
2772
  >(
2773
2773
  (args) => core.isEffect(args[1]),
2774
- (self, that, options) => zipWithOptions(self, that, (a, _) => a, options)
2774
+ (self, that, options) => {
2775
+ if (options?.concurrent !== true && (options?.batching === undefined || options.batching === false)) {
2776
+ return core.zipLeft(self, that)
2777
+ }
2778
+ return zipWithOptions(self, that, (a, _) => a, options)
2779
+ }
2775
2780
  )
2776
2781
 
2777
2782
  /** @internal */
@@ -2794,11 +2799,16 @@ export const zipRightOptions: {
2794
2799
  } = dual((args) => core.isEffect(args[1]), <A, E, R, A2, E2, R2>(
2795
2800
  self: Effect.Effect<A, E, R>,
2796
2801
  that: Effect.Effect<A2, E2, R2>,
2797
- options: {
2802
+ options?: {
2798
2803
  readonly concurrent?: boolean | undefined
2799
2804
  readonly batching?: boolean | "inherit" | undefined
2800
2805
  }
2801
- ): Effect.Effect<A2, E2 | E, R2 | R> => zipWithOptions(self, that, (_, b) => b, options))
2806
+ ): Effect.Effect<A2, E2 | E, R2 | R> => {
2807
+ if (options?.concurrent !== true && (options?.batching === undefined || options.batching === false)) {
2808
+ return core.zipRight(self, that)
2809
+ }
2810
+ return zipWithOptions(self, that, (_, b) => b, options)
2811
+ })
2802
2812
 
2803
2813
  /** @internal */
2804
2814
  export const zipWithOptions: {
@@ -1 +1 @@
1
- export const moduleVersion = "2.3.1"
1
+ export const moduleVersion = "2.3.2"
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.set = exports.clear = void 0;
7
- /**
8
- * Bun currently has a bug where `setTimeout` doesn't behave correctly with a 0ms delay.
9
- *
10
- * @see https://github.com/oven-sh/bun/issues/3333
11
- */
12
- /** @internal */
13
- const isBun = typeof process === "undefined" ? false : !!process?.isBun;
14
- /** @internal */
15
- const clear = exports.clear = isBun ? id => clearInterval(id) : id => clearTimeout(id);
16
- /** @internal */
17
- const set = exports.set = isBun ? (fn, ms) => {
18
- const id = setInterval(() => {
19
- fn();
20
- clearInterval(id);
21
- }, ms);
22
- return id;
23
- } : (fn, ms) => setTimeout(fn, ms);
24
- //# sourceMappingURL=timeout.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"timeout.js","names":["isBun","process","clear","exports","id","clearInterval","clearTimeout","set","fn","ms","setInterval","setTimeout"],"sources":["../../../src/internal/timeout.ts"],"sourcesContent":[null],"mappings":";;;;;;AAAA;;;;;AAMA;AACA,MAAMA,KAAK,GAAG,OAAOC,OAAO,KAAK,WAAW,GAAG,KAAK,GAAG,CAAC,CAAGA,OAAe,EAAED,KAAM;AAElF;AACO,MAAME,KAAK,GAAAC,OAAA,CAAAD,KAAA,GAAiCF,KAAK,GAAII,EAAE,IAAKC,aAAa,CAACD,EAAE,CAAC,GAAIA,EAAE,IAAKE,YAAY,CAACF,EAAE,CAAC;AAE/G;AACO,MAAMG,GAAG,GAAAJ,OAAA,CAAAI,GAAA,GAAmDP,KAAK,GACtE,CAACQ,EAAc,EAAEC,EAAU,KAAI;EAC7B,MAAML,EAAE,GAAGM,WAAW,CAAC,MAAK;IAC1BF,EAAE,EAAE;IACJH,aAAa,CAACD,EAAE,CAAC;EACnB,CAAC,EAAEK,EAAE,CAAC;EAEN,OAAOL,EAAE;AACX,CAAC,GACD,CAACI,EAAc,EAAEC,EAAU,KAAKE,UAAU,CAACH,EAAE,EAAEC,EAAE,CAAC"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Bun currently has a bug where `setTimeout` doesn't behave correctly with a 0ms delay.
3
- *
4
- * @see https://github.com/oven-sh/bun/issues/3333
5
- */
6
- export {};
7
- //# sourceMappingURL=timeout.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../../src/internal/timeout.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -1,18 +0,0 @@
1
- /**
2
- * Bun currently has a bug where `setTimeout` doesn't behave correctly with a 0ms delay.
3
- *
4
- * @see https://github.com/oven-sh/bun/issues/3333
5
- */
6
- /** @internal */
7
- const isBun = typeof process === "undefined" ? false : !!process?.isBun;
8
- /** @internal */
9
- export const clear = isBun ? id => clearInterval(id) : id => clearTimeout(id);
10
- /** @internal */
11
- export const set = isBun ? (fn, ms) => {
12
- const id = setInterval(() => {
13
- fn();
14
- clearInterval(id);
15
- }, ms);
16
- return id;
17
- } : (fn, ms) => setTimeout(fn, ms);
18
- //# sourceMappingURL=timeout.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"timeout.js","names":["isBun","process","clear","id","clearInterval","clearTimeout","set","fn","ms","setInterval","setTimeout"],"sources":["../../../src/internal/timeout.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;AAMA;AACA,MAAMA,KAAK,GAAG,OAAOC,OAAO,KAAK,WAAW,GAAG,KAAK,GAAG,CAAC,CAAGA,OAAe,EAAED,KAAM;AAElF;AACA,OAAO,MAAME,KAAK,GAAiCF,KAAK,GAAIG,EAAE,IAAKC,aAAa,CAACD,EAAE,CAAC,GAAIA,EAAE,IAAKE,YAAY,CAACF,EAAE,CAAC;AAE/G;AACA,OAAO,MAAMG,GAAG,GAAmDN,KAAK,GACtE,CAACO,EAAc,EAAEC,EAAU,KAAI;EAC7B,MAAML,EAAE,GAAGM,WAAW,CAAC,MAAK;IAC1BF,EAAE,EAAE;IACJH,aAAa,CAACD,EAAE,CAAC;EACnB,CAAC,EAAEK,EAAE,CAAC;EAEN,OAAOL,EAAE;AACX,CAAC,GACD,CAACI,EAAc,EAAEC,EAAU,KAAKE,UAAU,CAACH,EAAE,EAAEC,EAAE,CAAC"}
@@ -1,23 +0,0 @@
1
- /**
2
- * Bun currently has a bug where `setTimeout` doesn't behave correctly with a 0ms delay.
3
- *
4
- * @see https://github.com/oven-sh/bun/issues/3333
5
- */
6
-
7
- /** @internal */
8
- const isBun = typeof process === "undefined" ? false : !!((process as any)?.isBun)
9
-
10
- /** @internal */
11
- export const clear: (id: NodeJS.Timeout) => void = isBun ? (id) => clearInterval(id) : (id) => clearTimeout(id)
12
-
13
- /** @internal */
14
- export const set: (fn: () => void, ms: number) => NodeJS.Timeout = isBun ?
15
- (fn: () => void, ms: number) => {
16
- const id = setInterval(() => {
17
- fn()
18
- clearInterval(id)
19
- }, ms)
20
-
21
- return id
22
- } :
23
- (fn: () => void, ms: number) => setTimeout(fn, ms)