From e175eac7012c9ec8f9a0c4883951ad2f7b2ee48b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Tue, 24 Mar 2026 09:17:31 +0100 Subject: [PATCH] Add mapStructAt --- packages/effect-fc/src/Lens.ts | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/effect-fc/src/Lens.ts b/packages/effect-fc/src/Lens.ts index dc73344..f7f98c6 100644 --- a/packages/effect-fc/src/Lens.ts +++ b/packages/effect-fc/src/Lens.ts @@ -137,6 +137,23 @@ export const mapEffect: { )), })) +export const mapStructAt: { + ( + self: Lens, + key: K, + ): Lens + ( + key: K, + ): (self: Lens) => Lens +} = Function.dual(2, ( + self: Lens, + key: K, +): Lens => map( + self, + a => a[key], + (a, b) => Object.setPrototypeOf({ ...a, [key]: b }, Object.getPrototypeOf(a)), +)) + export const mapArrayAt: { ( self: Lens, @@ -275,14 +292,15 @@ Effect.gen(function*() { values: [13, 69, 1488] }) - const myValueLens = myChunkRef.pipe( + const myValueLens = ref.pipe( fromSubscriptionRef, - mapChunkAt(1), + mapStructAt("values"), + mapArrayAt(1), ) - console.log(yield* myChunkRef.get, yield* chunkValueLens.get) - yield* set(chunkValueLens, 22) - console.log(yield* myChunkRef.get, yield* chunkValueLens.get) + console.log(yield* ref.get, yield* myValueLens.get) + yield* set(myValueLens, 22) + console.log(yield* ref.get, yield* myValueLens.get) }).pipe( Effect.runSync )