@typed/fx 1.2.1 → 1.4.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.
Files changed (191) hide show
  1. package/dist/Subject/HoldSubject.d.ts +2 -2
  2. package/dist/Subject/HoldSubject.d.ts.map +1 -1
  3. package/dist/Subject/HoldSubject.js +3 -3
  4. package/dist/Subject/HoldSubject.js.map +1 -1
  5. package/dist/Subject/RefSubject.d.ts.map +1 -1
  6. package/dist/Subject/RefSubject.js +10 -10
  7. package/dist/Subject/RefSubject.js.map +1 -1
  8. package/dist/Subject/Subject.js +1 -1
  9. package/dist/Subject/Subject.js.map +1 -1
  10. package/dist/Subject/SynchronizedSubject.js +5 -5
  11. package/dist/Subject/SynchronizedSubject.js.map +1 -1
  12. package/dist/_internal/RefCounter.js +1 -1
  13. package/dist/_internal/RefCounter.js.map +1 -1
  14. package/dist/cjs/Subject/HoldSubject.d.ts +2 -2
  15. package/dist/cjs/Subject/HoldSubject.d.ts.map +1 -1
  16. package/dist/cjs/Subject/HoldSubject.js +3 -3
  17. package/dist/cjs/Subject/HoldSubject.js.map +1 -1
  18. package/dist/cjs/Subject/RefSubject.d.ts.map +1 -1
  19. package/dist/cjs/Subject/RefSubject.js +9 -9
  20. package/dist/cjs/Subject/RefSubject.js.map +1 -1
  21. package/dist/cjs/Subject/SynchronizedSubject.js +4 -4
  22. package/dist/cjs/Subject/SynchronizedSubject.js.map +1 -1
  23. package/dist/cjs/_internal/RefCounter.js +1 -1
  24. package/dist/cjs/_internal/RefCounter.js.map +1 -1
  25. package/dist/cjs/constructor/index.d.ts +0 -5
  26. package/dist/cjs/constructor/index.d.ts.map +1 -1
  27. package/dist/cjs/constructor/index.js +0 -5
  28. package/dist/cjs/constructor/index.js.map +1 -1
  29. package/dist/cjs/constructor/promiseFx.d.ts +0 -2
  30. package/dist/cjs/constructor/promiseFx.d.ts.map +1 -1
  31. package/dist/cjs/constructor/promiseFx.js +1 -5
  32. package/dist/cjs/constructor/promiseFx.js.map +1 -1
  33. package/dist/cjs/constructor/serviceWith.d.ts +1 -1
  34. package/dist/cjs/constructor/serviceWith.d.ts.map +1 -1
  35. package/dist/cjs/constructor/serviceWith.js +1 -1
  36. package/dist/cjs/constructor/serviceWith.js.map +1 -1
  37. package/dist/cjs/constructor/serviceWithEffect.d.ts +1 -1
  38. package/dist/cjs/constructor/serviceWithEffect.d.ts.map +1 -1
  39. package/dist/cjs/constructor/serviceWithEffect.js +1 -1
  40. package/dist/cjs/constructor/serviceWithEffect.js.map +1 -1
  41. package/dist/cjs/constructor/serviceWithFx.d.ts +1 -1
  42. package/dist/cjs/constructor/serviceWithFx.d.ts.map +1 -1
  43. package/dist/cjs/constructor/serviceWithFx.js +1 -1
  44. package/dist/cjs/constructor/serviceWithFx.js.map +1 -1
  45. package/dist/cjs/operator/catchAllDefect.d.ts.map +1 -1
  46. package/dist/cjs/operator/catchAllDefect.js +2 -1
  47. package/dist/cjs/operator/catchAllDefect.js.map +1 -1
  48. package/dist/cjs/operator/continueWith.js +1 -1
  49. package/dist/cjs/operator/continueWith.js.map +1 -1
  50. package/dist/cjs/operator/debounce.js +1 -1
  51. package/dist/cjs/operator/debounce.js.map +1 -1
  52. package/dist/cjs/operator/during.js +1 -1
  53. package/dist/cjs/operator/during.js.map +1 -1
  54. package/dist/cjs/operator/hold.d.ts.map +1 -1
  55. package/dist/cjs/operator/hold.js +8 -8
  56. package/dist/cjs/operator/hold.js.map +1 -1
  57. package/dist/cjs/operator/loop.js +1 -1
  58. package/dist/cjs/operator/loop.js.map +1 -1
  59. package/dist/cjs/operator/multicast.js +3 -3
  60. package/dist/cjs/operator/multicast.js.map +1 -1
  61. package/dist/cjs/operator/provideService.d.ts +1 -1
  62. package/dist/cjs/operator/provideService.d.ts.map +1 -1
  63. package/dist/cjs/operator/provideService.js.map +1 -1
  64. package/dist/cjs/operator/provideServiceEffect.d.ts +1 -1
  65. package/dist/cjs/operator/provideServiceEffect.d.ts.map +1 -1
  66. package/dist/cjs/operator/provideServiceEffect.js.map +1 -1
  67. package/dist/cjs/operator/race.js +1 -1
  68. package/dist/cjs/operator/race.js.map +1 -1
  69. package/dist/cjs/operator/skipRepeats.js +2 -2
  70. package/dist/cjs/operator/skipRepeats.js.map +1 -1
  71. package/dist/cjs/operator/switchMatch.js +1 -1
  72. package/dist/cjs/operator/switchMatch.js.map +1 -1
  73. package/dist/cjs/operator/tapDefect.d.ts.map +1 -1
  74. package/dist/cjs/operator/tapDefect.js +2 -1
  75. package/dist/cjs/operator/tapDefect.js.map +1 -1
  76. package/dist/cjs/run/collectAll.js +1 -1
  77. package/dist/cjs/run/collectAll.js.map +1 -1
  78. package/dist/cjs/run/collectN.js +1 -1
  79. package/dist/cjs/run/collectN.js.map +1 -1
  80. package/dist/cjs/run/reduce.js +1 -1
  81. package/dist/cjs/run/reduce.js.map +1 -1
  82. package/dist/constructor/done.js +1 -1
  83. package/dist/constructor/done.js.map +1 -1
  84. package/dist/constructor/empty.js +1 -1
  85. package/dist/constructor/empty.js.map +1 -1
  86. package/dist/constructor/fromArray.js +1 -1
  87. package/dist/constructor/fromArray.js.map +1 -1
  88. package/dist/constructor/fromEffect.js +1 -1
  89. package/dist/constructor/fromEffect.js.map +1 -1
  90. package/dist/constructor/fromIterable.js +1 -1
  91. package/dist/constructor/fromIterable.js.map +1 -1
  92. package/dist/constructor/index.d.ts +0 -5
  93. package/dist/constructor/index.d.ts.map +1 -1
  94. package/dist/constructor/index.js +0 -5
  95. package/dist/constructor/index.js.map +1 -1
  96. package/dist/constructor/never.js +1 -1
  97. package/dist/constructor/never.js.map +1 -1
  98. package/dist/constructor/promiseFx.d.ts +0 -2
  99. package/dist/constructor/promiseFx.d.ts.map +1 -1
  100. package/dist/constructor/promiseFx.js +0 -2
  101. package/dist/constructor/promiseFx.js.map +1 -1
  102. package/dist/constructor/service.d.ts +1 -1
  103. package/dist/constructor/service.d.ts.map +1 -1
  104. package/dist/constructor/service.js.map +1 -1
  105. package/dist/constructor/serviceWith.d.ts +1 -1
  106. package/dist/constructor/serviceWith.d.ts.map +1 -1
  107. package/dist/constructor/serviceWith.js +1 -1
  108. package/dist/constructor/serviceWith.js.map +1 -1
  109. package/dist/constructor/serviceWithEffect.d.ts +1 -1
  110. package/dist/constructor/serviceWithEffect.d.ts.map +1 -1
  111. package/dist/constructor/serviceWithEffect.js +1 -1
  112. package/dist/constructor/serviceWithEffect.js.map +1 -1
  113. package/dist/constructor/serviceWithFx.d.ts +1 -1
  114. package/dist/constructor/serviceWithFx.d.ts.map +1 -1
  115. package/dist/constructor/serviceWithFx.js +1 -1
  116. package/dist/constructor/serviceWithFx.js.map +1 -1
  117. package/dist/operator/catchAllDefect.d.ts.map +1 -1
  118. package/dist/operator/catchAllDefect.js +2 -1
  119. package/dist/operator/catchAllDefect.js.map +1 -1
  120. package/dist/operator/continueWith.js +2 -2
  121. package/dist/operator/continueWith.js.map +1 -1
  122. package/dist/operator/debounce.js +1 -1
  123. package/dist/operator/debounce.js.map +1 -1
  124. package/dist/operator/during.js +1 -1
  125. package/dist/operator/during.js.map +1 -1
  126. package/dist/operator/hold.d.ts.map +1 -1
  127. package/dist/operator/hold.js +8 -8
  128. package/dist/operator/hold.js.map +1 -1
  129. package/dist/operator/loop.js +1 -1
  130. package/dist/operator/loop.js.map +1 -1
  131. package/dist/operator/multicast.js +3 -3
  132. package/dist/operator/multicast.js.map +1 -1
  133. package/dist/operator/provideService.d.ts +1 -1
  134. package/dist/operator/provideService.d.ts.map +1 -1
  135. package/dist/operator/provideService.js.map +1 -1
  136. package/dist/operator/provideServiceEffect.d.ts +1 -1
  137. package/dist/operator/provideServiceEffect.d.ts.map +1 -1
  138. package/dist/operator/provideServiceEffect.js.map +1 -1
  139. package/dist/operator/race.js +1 -1
  140. package/dist/operator/race.js.map +1 -1
  141. package/dist/operator/scanEffect.js +1 -1
  142. package/dist/operator/scanEffect.js.map +1 -1
  143. package/dist/operator/skipRepeats.js +2 -2
  144. package/dist/operator/skipRepeats.js.map +1 -1
  145. package/dist/operator/switchMatch.js +1 -1
  146. package/dist/operator/switchMatch.js.map +1 -1
  147. package/dist/operator/tapDefect.d.ts.map +1 -1
  148. package/dist/operator/tapDefect.js +2 -1
  149. package/dist/operator/tapDefect.js.map +1 -1
  150. package/dist/run/collectAll.js +1 -1
  151. package/dist/run/collectAll.js.map +1 -1
  152. package/dist/run/collectN.js +1 -1
  153. package/dist/run/collectN.js.map +1 -1
  154. package/dist/run/reduce.js +1 -1
  155. package/dist/run/reduce.js.map +1 -1
  156. package/dist/run/run.js +1 -1
  157. package/dist/run/run.js.map +1 -1
  158. package/dist/tsconfig.cjs.build.tsbuildinfo +1 -1
  159. package/package.json +4 -4
  160. package/src/Subject/HoldSubject.ts +4 -4
  161. package/src/Subject/RefSubject.ts +9 -9
  162. package/src/Subject/SynchronizedSubject.ts +4 -4
  163. package/src/_internal/RefCounter.ts +1 -1
  164. package/src/constructor/index.ts +0 -5
  165. package/src/constructor/promiseFx.ts +0 -22
  166. package/src/constructor/serviceWith.ts +2 -2
  167. package/src/constructor/serviceWithEffect.ts +4 -4
  168. package/src/constructor/serviceWithFx.ts +5 -5
  169. package/src/operator/catchAllDefect.ts +2 -1
  170. package/src/operator/continueWith.ts +2 -2
  171. package/src/operator/debounce.ts +1 -1
  172. package/src/operator/during.ts +1 -1
  173. package/src/operator/hold.ts +9 -8
  174. package/src/operator/loop.ts +1 -1
  175. package/src/operator/multicast.ts +3 -3
  176. package/src/operator/provideService.ts +10 -6
  177. package/src/operator/provideServiceEffect.ts +9 -9
  178. package/src/operator/race.ts +1 -1
  179. package/src/operator/skipRepeats.ts +2 -2
  180. package/src/operator/switchMatch.ts +1 -1
  181. package/src/operator/tapDefect.ts +2 -1
  182. package/src/run/collectAll.ts +1 -1
  183. package/src/run/collectN.ts +1 -1
  184. package/src/run/reduce.ts +1 -1
  185. package/tsconfig.build.tsbuildinfo +1 -1
  186. package/tsconfig.cjs.build.json +2 -2
  187. package/src/constructor/service.ts +0 -9
  188. package/src/constructor/tryCatchPromise.ts +0 -11
  189. package/src/constructor/tryCatchPromiseAbort.ts +0 -11
  190. package/src/constructor/tryPromise.ts +0 -11
  191. package/src/constructor/tryPromiseAbort.ts +0 -10
@@ -1,5 +1,5 @@
1
1
  import { identity } from '@effect/data/Function'
2
- import { type MutableRef, make } from '@effect/data/MutableRef'
2
+ import * as MutableRef from '@effect/data/MutableRef'
3
3
  import { type Option, none } from '@effect/data/Option'
4
4
  import * as Effect from '@effect/io/Effect'
5
5
 
@@ -32,7 +32,7 @@ export namespace HoldSubject {
32
32
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
33
  export type OutputsOf<T> = [T] extends [Variance<infer _E, infer A>] ? A : never
34
34
 
35
- export function unsafeMake<E, A>(value: MutableRef<Option<A>> = make(none())): HoldSubject<E, A> {
35
+ export function unsafeMake<E, A>(value: MutableRef.MutableRef<Option<A>> = MutableRef.make(none())): HoldSubject<E, A> {
36
36
  return new HoldSubjectImpl(value)
37
37
  }
38
38
 
@@ -43,11 +43,11 @@ export namespace HoldSubject {
43
43
  };
44
44
  readonly [TypeId]: HoldSubject.Variance<E, A>[TypeId] = this[Subject.TypeId]
45
45
 
46
- constructor(value: MutableRef<Option<A>>) {
46
+ constructor(value: MutableRef.MutableRef<Option<A>>) {
47
47
  super(never, value)
48
48
  }
49
49
 
50
- readonly value = Effect.sync(() => this.current.get())
50
+ readonly value = Effect.sync(() => MutableRef.get(this.current))
51
51
  }
52
52
  }
53
53
 
@@ -48,14 +48,14 @@ export namespace RefSubject {
48
48
  const current = MutableRef.make(Option.some(initial()))
49
49
  const subject = HoldSubject.unsafeMake<never, A>(current)
50
50
 
51
- const getValue = () => pipe(current.get(), Option.getOrElse(initial))
51
+ const getValue = () => pipe(current, MutableRef.get, Option.getOrElse(initial))
52
52
 
53
53
  const modify = <B>(f: (a: A) => readonly [B, A]): Effect.Effect<never, never, B> =>
54
- Effect.suspendSucceed(() => {
54
+ Effect.suspend(() => {
55
55
  const currentValue = getValue()
56
56
  const [b, a] = f(currentValue)
57
57
 
58
- current.set(Option.some(a))
58
+ MutableRef.set(current, Option.some(a))
59
59
 
60
60
  if (eq(currentValue, a)) {
61
61
  return Effect.succeed(b)
@@ -80,9 +80,9 @@ export namespace RefSubject {
80
80
  modify,
81
81
  ...makeDerivations(modify, Effect.sync(getValue)),
82
82
  delete: Effect.sync(() => {
83
- const option = current.get()
83
+ const option = MutableRef.get(current)
84
84
  const reset = initial()
85
- current.set(Option.some(reset))
85
+ MutableRef.set(current, Option.some(reset))
86
86
 
87
87
  return Option.getOrElse(option, () => reset)
88
88
  }),
@@ -103,7 +103,7 @@ export namespace RefSubject {
103
103
  type Val = { readonly [K in keyof Subjects]: ValueOf<Subjects[K]> }
104
104
  const length = subjects.length
105
105
 
106
- const getUnderlyingValues = Effect.tuple(
106
+ const getUnderlyingValues = Effect.all(
107
107
  ...ReadonlyArray.mapNonEmpty(subjects, (s) => s.get),
108
108
  ) as Effect.Effect<never, never, Val>
109
109
 
@@ -128,7 +128,7 @@ export namespace RefSubject {
128
128
 
129
129
  // Override event to replicate events into underlying subjects
130
130
  const event = (val: Val) =>
131
- Effect.tuple(...ReadonlyArray.mapNonEmpty(subjects, (s, i) => s.event(val[i])))
131
+ Effect.all(...ReadonlyArray.mapNonEmpty(subjects, (s, i) => s.event(val[i])))
132
132
 
133
133
  // Override modify to replicate events into underlying subjects
134
134
  const modify = <B>(f: (a: Val) => readonly [B, Val]): Effect.Effect<never, never, B> =>
@@ -173,7 +173,7 @@ export namespace RefSubject {
173
173
  > {
174
174
  type Val = { readonly [K in keyof Subjects]: ValueOf<Subjects[K]> }
175
175
 
176
- const getUnderlyingValues = Effect.struct(
176
+ const getUnderlyingValues = Effect.all(
177
177
  ReadonlyRecord.map(subjects, (s) => s.get),
178
178
  ) as Effect.Effect<never, never, Val>
179
179
 
@@ -197,7 +197,7 @@ export namespace RefSubject {
197
197
 
198
198
  // Override event to replicate events into underlying subjects
199
199
  const event = (val: Val) =>
200
- Effect.struct(ReadonlyRecord.map(subjects, (s, i) => s.event(val[i])))
200
+ Effect.all(ReadonlyRecord.map(subjects, (s, i) => s.event(val[i])))
201
201
 
202
202
  // Override modify to replicate events into underlying subjects
203
203
  const modify = <B>(f: (a: Val) => readonly [B, Val]): Effect.Effect<never, never, B> =>
@@ -34,11 +34,11 @@ export namespace SynchronizedSubject {
34
34
 
35
35
  const getValue = () =>
36
36
  pipe(
37
- mutableRef.get(),
37
+ MutableRef.get(mutableRef),
38
38
  Option.getOrElse(() => {
39
39
  const a = initial()
40
40
 
41
- mutableRef.set(Option.some(a))
41
+ MutableRef.set(mutableRef, Option.some(a))
42
42
 
43
43
  return a
44
44
  }),
@@ -56,7 +56,7 @@ export namespace SynchronizedSubject {
56
56
  return b
57
57
  }
58
58
 
59
- mutableRef.set(Option.some(a))
59
+ MutableRef.set(mutableRef, Option.some(a))
60
60
 
61
61
  yield* $(subject.event(a))
62
62
 
@@ -100,7 +100,7 @@ export namespace SynchronizedSubject {
100
100
  delete: Effect.sync(() => {
101
101
  const value = getValue()
102
102
 
103
- mutableRef.set(Option.some(value))
103
+ MutableRef.set(mutableRef, Option.some(value))
104
104
 
105
105
  return value
106
106
  }),
@@ -33,7 +33,7 @@ export class RefCounter {
33
33
 
34
34
  readonly wait = Deferred.await(this.deferred)
35
35
 
36
- private checkShouldClose = Effect.suspendSucceed(() => {
36
+ private checkShouldClose = Effect.suspend(() => {
37
37
  const interrupt = this.fiber ? Fiber.interrupt(this.fiber) : Effect.unit()
38
38
 
39
39
  this.fiber = undefined
@@ -31,15 +31,10 @@ export * from './promiseAbort.js'
31
31
  export * from './promiseFx.js'
32
32
  export * from './random.js'
33
33
  export * from './scheduled.js'
34
- export * from './service.js'
35
34
  export * from './serviceWith.js'
36
35
  export * from './serviceWithEffect.js'
37
36
  export * from './serviceWithFx.js'
38
37
  export * from './succeed.js'
39
38
  export * from './suspend.js'
40
39
  export * from './sync.js'
41
- export * from './tryCatchPromise.js'
42
- export * from './tryCatchPromiseAbort.js'
43
- export * from './tryPromise.js'
44
- export * from './tryPromiseAbort.js'
45
40
  export * from './unit.js'
@@ -20,25 +20,3 @@ export const promiseInterruptFx = <R, E, A>(
20
20
  Effect.matchCauseEffect(sink.error, (fx) => fx.run(sink)),
21
21
  ),
22
22
  )
23
-
24
- export const tryCatchPromiseFx = <R, E, A, E2>(
25
- f: () => Promise<Fx<R, E, A>>,
26
- onError: (u: unknown) => E2,
27
- ): Fx<R, E | E2, A> =>
28
- Fx((sink) =>
29
- pipe(
30
- Effect.tryCatchPromise(f, onError),
31
- Effect.matchCauseEffect(sink.error, (fx) => fx.run(sink)),
32
- ),
33
- )
34
-
35
- export const tryCatchPromiseInterruptFx = <R, E, A, E2>(
36
- f: (signal: AbortSignal) => Promise<Fx<R, E, A>>,
37
- onError: (u: unknown) => E2,
38
- ): Fx<R, E | E2, A> =>
39
- Fx((sink) =>
40
- pipe(
41
- Effect.tryCatchPromiseInterrupt(f, onError),
42
- Effect.matchCauseEffect(sink.error, (fx) => fx.run(sink)),
43
- ),
44
- )
@@ -5,6 +5,6 @@ import type { Fx } from '../Fx.js'
5
5
 
6
6
  import { fromEffect } from './fromEffect.js'
7
7
 
8
- export const serviceWith: <T>(tag: Tag<T>) => <A>(f: (a: T) => A) => Fx<T, never, A> =
8
+ export const serviceWith: <I, T>(tag: Tag<I, T>) => <A>(f: (a: T) => A) => Fx<I, never, A> =
9
9
  (tag) => (f) =>
10
- fromEffect(Effect.serviceWith(tag, f))
10
+ fromEffect(Effect.map(tag, f))
@@ -5,7 +5,7 @@ import type { Fx } from '../Fx.js'
5
5
 
6
6
  import { fromEffect } from './fromEffect.js'
7
7
 
8
- export const serviceWithEffect: <T>(
9
- tag: Tag<T>,
10
- ) => <R, E, A>(f: (a: T) => Effect.Effect<R, E, A>) => Fx<T | R, E, A> = (tag) => (f) =>
11
- fromEffect(Effect.serviceWithEffect(tag, f))
8
+ export const serviceWithEffect: <I, T>(
9
+ tag: Tag<I, T>,
10
+ ) => <R, E, A>(f: (a: T) => Effect.Effect<R, E, A>) => Fx<I | R, E, A> = (tag) => (f) =>
11
+ fromEffect(Effect.flatMap(tag, f))
@@ -4,16 +4,16 @@ import * as Effect from '@effect/io/Effect'
4
4
  import { Fx } from '../Fx.js'
5
5
 
6
6
  export const serviceWithFx =
7
- <T>(tag: Tag<T>) =>
8
- <R, E, A>(f: (t: T) => Fx<R, E, A>): Fx<T | R, E, A> =>
7
+ <I, S>(tag: Tag<I, S>) =>
8
+ <R, E, A>(f: (s: S) => Fx<R, E, A>): Fx<I | R, E, A> =>
9
9
  new ServiceWithFx(tag, f)
10
10
 
11
- class ServiceWithFx<T, R, E, A> extends Fx.Variance<T | R, E, A> implements Fx<T | R, E, A> {
12
- constructor(readonly tag: Tag<T>, readonly f: (a: T) => Fx<R, E, A>) {
11
+ class ServiceWithFx<I, S, R, E, A> extends Fx.Variance<I | R, E, A> implements Fx<I | R, E, A> {
12
+ constructor(readonly tag: Tag<I, S>, readonly f: (a: S) => Fx<R, E, A>) {
13
13
  super()
14
14
  }
15
15
 
16
16
  run<R2>(sink: Fx.Sink<R2, E, A>) {
17
- return Effect.serviceWithEffect(this.tag, (a) => this.f(a).run(sink))
17
+ return Effect.flatMap(this.tag, (a) => this.f(a).run(sink))
18
18
  }
19
19
  }
@@ -1,5 +1,6 @@
1
1
  import { pipe } from '@effect/data/Function'
2
2
  import { match } from '@effect/data/Option'
3
+ import * as Chunk from '@effect/data/Chunk'
3
4
  import * as Cause from '@effect/io/Cause'
4
5
 
5
6
  import type { Fx } from '../Fx.js'
@@ -14,7 +15,7 @@ export function catchAllDefect<R2, E2, B>(f: (defect: unknown) => Fx<R2, E2, B>)
14
15
  catchAllCause(
15
16
  (cause): Fx<R2, E | E2, B> =>
16
17
  pipe(
17
- Cause.defects(cause).get(0),
18
+ Chunk.get(Cause.defects(cause), 0),
18
19
  match(() => failCause(cause), f),
19
20
  ),
20
21
  ),
@@ -1,4 +1,4 @@
1
- import { suspendSucceed } from '@effect/io/Effect'
1
+ import { suspend } from '@effect/io/Effect'
2
2
 
3
3
  import { Fx } from '../Fx.js'
4
4
 
@@ -24,5 +24,5 @@ class ContinueWithSink<R, E, A, R2, E2, B> {
24
24
 
25
25
  event = this.sink.event
26
26
  error = this.sink.error
27
- end = suspendSucceed(() => this.f().run(this.sink))
27
+ end = suspend(() => this.f().run(this.sink))
28
28
  }
@@ -27,7 +27,7 @@ class DebounceFx<R, E, A> extends Fx.Variance<R, E, A> implements Fx<R, E, A> {
27
27
  return fx.run(
28
28
  Fx.Sink(
29
29
  (a: A) =>
30
- Effect.suspendSucceed(() =>
30
+ Effect.suspend(() =>
31
31
  pipe(
32
32
  scheduledFiber ? Fiber.interrupt(scheduledFiber) : counter.increment,
33
33
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -42,7 +42,7 @@ class DuringFx<R, E, A, R2, E2, R3, E3, B>
42
42
  signal.run(
43
43
  Fx.Sink(
44
44
  (endSignal) =>
45
- Effect.suspendSucceed(() => {
45
+ Effect.suspend(() => {
46
46
  shouldRun = true
47
47
 
48
48
  return endSignal.run(Fx.Sink(() => earlyExit, sink.error, earlyExit))
@@ -34,8 +34,8 @@ export class HoldFx<R, E, A> extends MulticastFx<R, E, A> implements Fx<R, E, A>
34
34
  }
35
35
 
36
36
  run<R2>(sink: Fx.Sink<R2, E, A>): Effect.Effect<Scope | R | R2, never, void> {
37
- return Effect.suspendSucceed(() => {
38
- if (Option.isSome(this.current.get())) {
37
+ return Effect.suspend(() => {
38
+ if (Option.isSome(MutableRef.get(this.current))) {
39
39
  return pipe(
40
40
  this.scheduleFlush(sink),
41
41
  Effect.flatMap(() => super.run(sink)),
@@ -47,7 +47,7 @@ export class HoldFx<R, E, A> extends MulticastFx<R, E, A> implements Fx<R, E, A>
47
47
  }
48
48
 
49
49
  event(a: A) {
50
- return Effect.suspendSucceed(() => {
50
+ return Effect.suspend(() => {
51
51
  this.addValue(a)
52
52
 
53
53
  return pipe(
@@ -58,7 +58,7 @@ export class HoldFx<R, E, A> extends MulticastFx<R, E, A> implements Fx<R, E, A>
58
58
  }
59
59
 
60
60
  error(cause: Cause.Cause<E>) {
61
- return Effect.suspendSucceed(() =>
61
+ return Effect.suspend(() =>
62
62
  pipe(
63
63
  this.flushPending(),
64
64
  Effect.flatMap(() => super.error(cause)),
@@ -67,7 +67,7 @@ export class HoldFx<R, E, A> extends MulticastFx<R, E, A> implements Fx<R, E, A>
67
67
  }
68
68
 
69
69
  get end() {
70
- return Effect.suspendSucceed(() =>
70
+ return Effect.suspend(() =>
71
71
  pipe(
72
72
  this.flushPending(),
73
73
  Effect.flatMap(() => super.end),
@@ -76,11 +76,12 @@ export class HoldFx<R, E, A> extends MulticastFx<R, E, A> implements Fx<R, E, A>
76
76
  }
77
77
 
78
78
  protected scheduleFlush(sink: Fx.Sink<any, E, A>) {
79
- return Effect.suspendSucceed(() => {
79
+ return Effect.suspend(() => {
80
80
  this.pendingSinks.push([
81
81
  sink,
82
82
  pipe(
83
- this.current.get(),
83
+ this.current,
84
+ MutableRef.get,
84
85
  Option.match(
85
86
  () => [],
86
87
  (a) => [a],
@@ -137,7 +138,7 @@ export class HoldFx<R, E, A> extends MulticastFx<R, E, A> implements Fx<R, E, A>
137
138
  }
138
139
 
139
140
  protected addValue(a: A) {
140
- this.current.set(Option.some(a))
141
+ MutableRef.set(this.current, Option.some(a))
141
142
  this.pendingSinks.forEach(([, events]) => events.push(a))
142
143
  }
143
144
  }
@@ -30,7 +30,7 @@ class LoopSink<R, E, A, B, C> implements Fx.Sink<R, E, A> {
30
30
  ) {}
31
31
 
32
32
  readonly event = (a: A) =>
33
- Effect.suspendSucceed(() => {
33
+ Effect.suspend(() => {
34
34
  const [c, b] = this.f(this.acc, a)
35
35
 
36
36
  this.acc = b
@@ -55,13 +55,13 @@ export class MulticastFx<R, E, A>
55
55
  }
56
56
 
57
57
  event(a: A) {
58
- return Effect.suspendSucceed(() =>
58
+ return Effect.suspend(() =>
59
59
  Effect.forEachDiscard(this.observers.slice(), (observer) => this.runEvent(a, observer)),
60
60
  )
61
61
  }
62
62
 
63
63
  error(cause: Cause<E>) {
64
- return Effect.suspendSucceed(() =>
64
+ return Effect.suspend(() =>
65
65
  pipe(
66
66
  Effect.forEachDiscard(this.observers.slice(), (observer) => this.runError(cause, observer)),
67
67
  Effect.tap(() => this.cleanup()),
@@ -70,7 +70,7 @@ export class MulticastFx<R, E, A>
70
70
  }
71
71
 
72
72
  get end(): Effect.Effect<never, never, void> {
73
- return Effect.suspendSucceed(() =>
73
+ return Effect.suspend(() =>
74
74
  pipe(
75
75
  this.observers.slice(),
76
76
  Effect.forEachDiscard((observer) => this.runEnd(observer)),
@@ -4,18 +4,22 @@ import * as Effect from '@effect/io/Effect'
4
4
 
5
5
  import { Fx } from '../Fx.js'
6
6
 
7
- export function provideService<S>(tag: Context.Tag<S>) {
7
+ export function provideService<I, S>(tag: Context.Tag<I, S>) {
8
8
  return (service: S) => {
9
- return <R, E, A>(self: Fx<R | S, E, A>): Fx<Exclude<R, S>, E, A> =>
9
+ return <R, E, A>(self: Fx<R | I, E, A>): Fx<Exclude<R, I>, E, A> =>
10
10
  new ProvideServiceFx(self, tag, service)
11
11
  }
12
12
  }
13
13
 
14
- class ProvideServiceFx<R, E, A, S>
15
- extends Fx.Variance<Exclude<R, S>, E, A>
16
- implements Fx<Exclude<R, S>, E, A>
14
+ class ProvideServiceFx<R, E, A, I, S>
15
+ extends Fx.Variance<Exclude<R, I>, E, A>
16
+ implements Fx<Exclude<R, I>, E, A>
17
17
  {
18
- constructor(readonly self: Fx<R | S, E, A>, readonly tag: Context.Tag<S>, readonly service: S) {
18
+ constructor(
19
+ readonly self: Fx<R | I, E, A>,
20
+ readonly tag: Context.Tag<I, S>,
21
+ readonly service: S,
22
+ ) {
19
23
  super()
20
24
  }
21
25
 
@@ -5,21 +5,21 @@ import type { Scope } from '@effect/io/Scope'
5
5
 
6
6
  import { Fx } from '../Fx.js'
7
7
 
8
- export function provideServiceEffect<S, R2, E2>(
9
- tag: Context.Tag<S>,
8
+ export function provideServiceEffect<I, S, R2, E2>(
9
+ tag: Context.Tag<I, S>,
10
10
  service: Effect.Effect<R2, E2, S>,
11
11
  ) {
12
- return <R, E, A>(self: Fx<R | S, E, A>): Fx<Exclude<R | R2, S>, E | E2, A> =>
12
+ return <R, E, A>(self: Fx<R | I, E, A>): Fx<Exclude<R | R2, I>, E | E2, A> =>
13
13
  new ProvideServiceEffectFx(self, tag, service)
14
14
  }
15
15
 
16
- class ProvideServiceEffectFx<R, E, A, R2, E2, S>
17
- extends Fx.Variance<Exclude<R | R2, S>, E | E2, A>
18
- implements Fx<Exclude<R | R2, S>, E | E2, A>
16
+ class ProvideServiceEffectFx<R, E, A, R2, E2, I, S>
17
+ extends Fx.Variance<Exclude<R | R2, I>, E | E2, A>
18
+ implements Fx<Exclude<R | R2, I>, E | E2, A>
19
19
  {
20
20
  constructor(
21
- readonly self: Fx<R | S, E, A>,
22
- readonly tag: Context.Tag<S>,
21
+ readonly self: Fx<R | I, E, A>,
22
+ readonly tag: Context.Tag<I, S>,
23
23
  readonly service: Effect.Effect<R2, E2, S>,
24
24
  ) {
25
25
  super()
@@ -30,6 +30,6 @@ class ProvideServiceEffectFx<R, E, A, R2, E2, S>
30
30
  this.self.run(sink),
31
31
  Effect.provideServiceEffect(this.tag, this.service),
32
32
  Effect.matchCauseEffect(sink.error, Effect.succeed),
33
- ) as Effect.Effect<Exclude<R | R2 | R3 | Scope, S>, never, unknown>
33
+ ) as Effect.Effect<Exclude<R | R2 | R3 | Scope, I>, never, unknown>
34
34
  }
35
35
  }
@@ -57,7 +57,7 @@ class RaceAllFx<Streams extends readonly Fx<any, any, any>[]>
57
57
  run(sink.event, sink.error, sink.end),
58
58
  Effect.scheduleForked(asap), // Schedule starts so that all Scopes can be returned *before* attempting to cleanup
59
59
  Effect.as(scope),
60
- Effect.provideService(Scope.Tag, scope),
60
+ Effect.provideService(Scope.Scope, scope),
61
61
  ),
62
62
  ),
63
63
  ),
@@ -22,13 +22,13 @@ class SkipRepeatsWithFx<R, E, A> extends Fx.Variance<R, E, A> implements Fx<R, E
22
22
  }
23
23
 
24
24
  run<R2>(sink: Fx.Sink<R2, E, A>) {
25
- return Effect.suspendSucceed(() => {
25
+ return Effect.suspend(() => {
26
26
  let previous: Option.Option<A> = Option.none()
27
27
 
28
28
  return this.self.run({
29
29
  ...sink,
30
30
  event: (a) =>
31
- Effect.suspendSucceed(() => {
31
+ Effect.suspend(() => {
32
32
  if (Option.isNone(previous) || !this.equals(previous.value, a)) {
33
33
  previous = Option.some(a)
34
34
 
@@ -49,7 +49,7 @@ class SwitchMatchFx<R, E, A, R2, E2, B, R3, E3, C>
49
49
 
50
50
  let firstError = true
51
51
 
52
- const handleError = Effect.suspendSucceed(() =>
52
+ const handleError = Effect.suspend(() =>
53
53
  firstError ? ((firstError = false), Effect.asUnit(counter.decrement)) : Effect.unit(),
54
54
  )
55
55
 
@@ -1,5 +1,6 @@
1
1
  import { pipe } from '@effect/data/Function'
2
2
  import { match } from '@effect/data/Option'
3
+ import * as Chunk from '@effect/data/Chunk'
3
4
  import * as Cause from '@effect/io/Cause'
4
5
  import * as Effect from '@effect/io/Effect'
5
6
 
@@ -14,7 +15,7 @@ export function tapDefect<R2, E2, B>(f: (defect: unknown) => Effect.Effect<R2, E
14
15
  tapCause(
15
16
  (cause): Effect.Effect<R2, E | E2, B> =>
16
17
  pipe(
17
- Cause.defects(cause).get(0),
18
+ Chunk.get(Cause.defects(cause), 0),
18
19
  match(() => Effect.failCause(cause), f),
19
20
  ),
20
21
  ),
@@ -6,7 +6,7 @@ import type { Fx } from '../Fx.js'
6
6
  import { reduce } from './reduce.js'
7
7
 
8
8
  export const collectAll = <R, E, A>(fx: Fx<R, E, A>): Effect.Effect<R, E, readonly A[]> =>
9
- Effect.suspendSucceed(() =>
9
+ Effect.suspend(() =>
10
10
  pipe(
11
11
  fx,
12
12
  reduce([] as A[], (acc, a) => {
@@ -9,7 +9,7 @@ import { reduce } from './reduce.js'
9
9
  export const collectN =
10
10
  (amount: number) =>
11
11
  <R, E, A>(fx: Fx<R, E, A>): Effect.Effect<R, E, readonly A[]> =>
12
- Effect.suspendSucceed(() =>
12
+ Effect.suspend(() =>
13
13
  pipe(
14
14
  fx,
15
15
  take(amount),
package/src/run/reduce.ts CHANGED
@@ -9,7 +9,7 @@ export const reduce: <B, A>(
9
9
  seed: B,
10
10
  f: (acc: B, a: A) => B,
11
11
  ) => <R, E>(fx: Fx<R, E, A>) => Effect.Effect<R, E, B> = (seed, f) => (fx) =>
12
- Effect.suspendSucceed(() => {
12
+ Effect.suspend(() => {
13
13
  let acc = seed
14
14
 
15
15
  return pipe(