MCPcopy
hub / github.com/Effect-TS/effect / exactlyOnce

Function exactlyOnce

packages/effect/test/Effect/filtering.test.ts:10–21  ·  view source on GitHub ↗
(
  value: A,
  f: (_: Effect.Effect<A>) => Effect.Effect<A1, string, R>
)

Source from the content-addressed store, hash-verified

8import { strictEqual } from "node:assert"
9
10const 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
23describe("Effect", () => {
24 it.effect("filter - filters a collection using an effectual predicate", () =>

Callers 1

filtering.test.tsFile · 0.85

Calls 6

fFunction · 0.70
makeMethod · 0.65
updateMethod · 0.65
getMethod · 0.65
failMethod · 0.65
pipeFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…