From 45c854a8d0dab1ac4171391fd9ead9dab22a5931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Mon, 23 Mar 2026 03:03:35 +0100 Subject: [PATCH] Fix make --- packages/effect-fc/src/Lens.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/effect-fc/src/Lens.ts b/packages/effect-fc/src/Lens.ts index 3ecc1dc..cd49464 100644 --- a/packages/effect-fc/src/Lens.ts +++ b/packages/effect-fc/src/Lens.ts @@ -1,4 +1,4 @@ -import { Effect, Pipeable, Predicate, Readable, Stream, Subscribable, SubscriptionRef } from "effect" +import { Effect, Pipeable, Predicate, Readable, Stream, Subscribable, type SubscriptionRef } from "effect" import * as Writable from "./Writable.js" @@ -24,17 +24,23 @@ export const LensPrototype: LensPrototype = Object.freeze({ export const isLens = (u: unknown): u is Lens => Predicate.hasProperty(u, LensTypeId) -export const make = (options: { - readonly get: Effect.Effect - readonly changes: Stream.Stream - readonly set: (value: A) => Effect.Effect -}): Lens => Object.setPrototypeOf({ +export const make = ( + options: { + readonly get: Effect.Effect + readonly changes: Stream.Stream + } & ( + | { readonly modify: (f: (a: A) => readonly [B, A]) => Effect.Effect } + | { readonly set: (value: A) => Effect.Effect } + ) +): Lens => Object.setPrototypeOf({ get: options.get, changes: options.changes, - modify: (f: (a: A) => readonly [B, A]) => Effect.flatMap(options.get, a => { - const [b, next] = f(a) - return Effect.map(options.set(next), () => b) - }), + modify: Predicate.hasProperty(options, "modify") + ? options.modify + : (f: (a: A) => readonly [B, A]) => Effect.flatMap(options.get, a => { + const [b, next] = f(a) + return Effect.map(options.set(next), () => b) + }), }, LensPrototype) /** @@ -45,7 +51,7 @@ export const fromSubscriptionRef = ( ): Lens => make({ get: ref.get, changes: ref.changes, - set: (v: A) => SubscriptionRef.set(ref, v), + modify: ref.modify, }) export const unwrap = (