From 571592b3dc6ec9739c4940f9f2616e293a685bee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Tue, 24 Mar 2026 23:15:25 +0100 Subject: [PATCH] Add fromSynchronizedRef --- packages/effect-fc/src/Lens.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/effect-fc/src/Lens.ts b/packages/effect-fc/src/Lens.ts index f347cd0..112de62 100644 --- a/packages/effect-fc/src/Lens.ts +++ b/packages/effect-fc/src/Lens.ts @@ -1,4 +1,4 @@ -import { Array, Chunk, Effect, Function, Pipeable, Predicate, Readable, type Ref, Stream, Subscribable, type SubscriptionRef } from "effect" +import { Array, Chunk, Effect, Function, Pipeable, Predicate, Readable, Stream, Subscribable, type SubscriptionRef, type SynchronizedRef } from "effect" import type { NoSuchElementException } from "effect/Cause" @@ -92,25 +92,19 @@ export const fromSubscriptionRef = ( }) /** - * Creates a `Lens` that proxies a `Ref`. + * Creates a `Lens` that proxies a `SynchronizedRef`. * - * Note: since `Ref` does not provide any kind of reactivity mechanism, the produced `Lens` will be non-reactive. + * Note: since `SynchronizedRef` does not provide any kind of reactivity mechanism, the produced `Lens` will be non-reactive. * This means its `changes` stream will only emit the current value once when evaluated and nothing else. */ -export const fromRef = ( - ref: Ref.Ref +export const fromSynchronizedRef = ( + ref: SynchronizedRef.SynchronizedRef ): Lens => make({ get get() { return ref.get }, get changes() { return Stream.unwrap(Effect.map(ref.get, Stream.make)) }, modify: ( f: (a: A) => Effect.Effect - ) => Effect.flatMap(ref.get, a => Effect.flatMap( - f(a), - ([b, next]) => Effect.flatMap( - ref.set(next), - () => Effect.succeed(b), - ), - )), + ) => ref.modifyEffect(f), }) /**