From b8ad8a94c92cd67c01f42220fa1354cc62b7acfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Mon, 23 Mar 2026 08:06:47 +0100 Subject: [PATCH] Fix --- packages/effect-fc/src/Lens.ts | 38 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/effect-fc/src/Lens.ts b/packages/effect-fc/src/Lens.ts index 1f23b89..a7dd2f9 100644 --- a/packages/effect-fc/src/Lens.ts +++ b/packages/effect-fc/src/Lens.ts @@ -5,34 +5,38 @@ export const LensTypeId: unique symbol = Symbol.for("@effect-fc/Lens/Lens") export type LensTypeId = typeof LensTypeId export interface Lens -extends Subscribable.Subscribable, LensPrototype { - readonly set: (a: A) => Effect.Effect -} - - -export interface LensPrototype extends Pipeable.Pipeable { +extends Subscribable.Subscribable { readonly [LensTypeId]: LensTypeId + + readonly set: (a: A) => Effect.Effect readonly modify: ( f: (a: A) => Effect.Effect ) => Effect.Effect } -export const LensPrototype: LensPrototype = Object.freeze({ - ...Pipeable.Prototype, - [Readable.TypeId]: Readable.TypeId, - [Subscribable.TypeId]: Subscribable.TypeId, - [LensTypeId]: LensTypeId, +export class LensImpl +extends Pipeable.Class() implements Lens { + readonly [Readable.TypeId]: Readable.TypeId = Readable.TypeId + readonly [Subscribable.TypeId]: Subscribable.TypeId = Subscribable.TypeId + readonly [LensTypeId]: LensTypeId = LensTypeId - modify( - this: Lens, - f: (a: A) => Effect.Effect, + constructor( + readonly get: Effect.Effect, + readonly changes: Stream.Stream, + readonly set: (a: A) => Effect.Effect, + ) { + super() + } + + modify( + f: (a: A) => Effect.Effect ) { return Effect.flatMap( this.get, a => Effect.flatMap(f(a), ([b, next]) => Effect.as(this.set(next), b) )) - }, -} as const) + } +} export const isLens = (u: unknown): u is Lens => Predicate.hasProperty(u, LensTypeId) @@ -43,7 +47,7 @@ export const make = ( readonly changes: Stream.Stream readonly set: (a: A) => Effect.Effect } -): Lens => Object.setPrototypeOf({ ...options }, LensPrototype) +): Lens => new LensImpl(options.get, options.changes, options.set) /** * Creates a `Lens` that directly proxies a `SubscriptionRef`.