| 8 | import { strictEqual } from "node:assert" |
| 9 | |
| 10 | const exactlyOnce = <R, A, A1>( |
| 11 | value: A, |
| 12 | f: (_: Effect.Effect<A>) => Effect.Effect<A1, string, R> |
| 13 | ): Effect.Effect<A1, string, R> => { |
| 14 | return Effect.gen(function*() { |
| 15 | const ref = yield* (Ref.make(0)) |
| 16 | const res = yield* (f(pipe(Ref.update(ref, (n) => n + 1), Effect.zipRight(Effect.succeed(value))))) |
| 17 | const count = yield* (Ref.get(ref)) |
| 18 | yield* (count !== 1 ? Effect.fail("Accessed more than once") : Effect.void) |
| 19 | return res |
| 20 | }) |
| 21 | } |
| 22 | |
| 23 | describe("Effect", () => { |
| 24 | it.effect("filter - filters a collection using an effectual predicate", () => |