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

Function refReader

packages/effect/test/Channel/reading.test.ts:44–61  ·  view source on GitHub ↗
(
  ref: Ref.Ref<Array<A>>
)

Source from the content-addressed store, hash-verified

42}
43
44export const refReader = <A>(
45 ref: Ref.Ref<Array<A>>
46): Channel.Channel<A, unknown, never, unknown, void, unknown> => {
47 return pipe(
48 Channel.fromEffect(
49 Ref.modify(ref, (array) => {
50 if (Array.isEmptyReadonlyArray(array)) {
51 return [Option.none(), Array.empty<A>()] as const
52 }
53 return [Option.some(array[0]!), array.slice(1)] as const
54 })
55 ),
56 Channel.flatMap(Option.match({
57 onNone: () => Channel.void,
58 onSome: (i) => Channel.flatMap(Channel.write(i), () => refReader(ref))
59 }))
60 )
61}
62
63describe("Channel", () => {
64 it.effect("simple reads", () =>

Callers 1

reading.test.tsFile · 0.85

Calls 4

fromEffectMethod · 0.80
modifyMethod · 0.65
writeMethod · 0.65
pipeFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…