From 087317171a04920d73948481153b5bcf98c3da79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Tue, 24 Mar 2026 11:10:59 +0100 Subject: [PATCH] Fix --- packages/effect-fc/src/Lens.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packages/effect-fc/src/Lens.ts b/packages/effect-fc/src/Lens.ts index 5a8596f..053ebaf 100644 --- a/packages/effect-fc/src/Lens.ts +++ b/packages/effect-fc/src/Lens.ts @@ -156,6 +156,31 @@ export const mapField: { (a, b) => Object.setPrototypeOf({ ...a, [key]: b }, Object.getPrototypeOf(a)), )) +export declare namespace mapMutableField { + type IfEquals = (() => T extends X ? 1 : 2) extends (() => T extends Y ? 1 : 2) ? A : B + export type WritableKeys = { + [K in keyof T]-?: IfEquals< + { [P in K]: T[K] }, + { -readonly [P in K]: T[K] }, + K, + never + > + }[keyof T] +} + +export const mapMutableField: { + , ER, EW, RR, RW>( + self: Lens, + key: K, + ): Lens + , ER, EW, RR, RW>( + key: K, + ): (self: Lens) => Lens +} = Function.dual(2, , ER, EW, RR, RW>( + self: Lens, + key: K, +): Lens => map(self, a => a[key], (a, b) => { a[key] = b; return a })) + export const mapArrayAt: { ( self: Lens, @@ -287,3 +312,9 @@ export const updateAndGetEffect: { next => Effect.succeed([next, next] as const), )), ) + + +declare const lens: Lens<{ readonly a: string, b: number }> +const t = lens.pipe( + mapMutableField("b") +)