From 1e068af09c5d4c41d3387185148b0c63d7b42a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Mon, 30 Mar 2026 13:27:54 +0200 Subject: [PATCH 1/3] Add Subscribable utils --- packages/effect-lens/src/Subscribable.ts | 37 +++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/effect-lens/src/Subscribable.ts b/packages/effect-lens/src/Subscribable.ts index c88a108..10cf991 100644 --- a/packages/effect-lens/src/Subscribable.ts +++ b/packages/effect-lens/src/Subscribable.ts @@ -1,9 +1,44 @@ -import { Array, Chunk, Function, Subscribable } from "effect" +import { Array, Chunk, Effect, Function, Option, Subscribable } from "effect" import type { NoSuchElementException } from "effect/Cause" export * from "effect/Subscribable" +/** + * Maps over an `Option` value in the `Subscribable`. + */ +export const mapOption: { + ( + self: Subscribable.Subscribable, E, R>, + f: (a: A) => B, + ): Subscribable.Subscribable, E, R> + ( + f: (a: A) => B, + ): (self: Subscribable.Subscribable, E, R>) => Subscribable.Subscribable, E, R> +} = Function.dual(2, ( + self: Subscribable.Subscribable, E, R>, + f: (a: A) => B, +): Subscribable.Subscribable, E, R> => Subscribable.map(self, Option.map(f))) + +/** + * Maps over an `Option` value in the `Subscribable` with an Effect. + */ +export const mapOptionEffect: { + ( + self: Subscribable.Subscribable, E, R>, + f: (a: A) => Effect.Effect, + ): Subscribable.Subscribable, E | E2, R> + ( + f: (a: A) => Effect.Effect, + ): (self: Subscribable.Subscribable, E, R>) => Subscribable.Subscribable, E | E2, R> +} = Function.dual(2, ( + self: Subscribable.Subscribable, E, R>, + f: (a: A) => Effect.Effect, +): Subscribable.Subscribable, E | E2, R> => Subscribable.mapEffect(self, Option.match({ + onSome: a => Effect.map(f(a), Option.some), + onNone: () => Effect.succeed(Option.none()), +}))) + /** * Narrows the focus to a field of an object. */ -- 2.49.1 From 41e8685f3687c229abc51085b4a941118ef624bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Mon, 30 Mar 2026 14:11:01 +0200 Subject: [PATCH 2/3] Fix --- packages/effect-lens/src/Lens.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/effect-lens/src/Lens.ts b/packages/effect-lens/src/Lens.ts index f265eee..bdb5ffe 100644 --- a/packages/effect-lens/src/Lens.ts +++ b/packages/effect-lens/src/Lens.ts @@ -274,14 +274,14 @@ export const mapStream: { * Narrows the focus to a field of an object. Replaces the object in an immutable fashion when written to. */ export const focusObjectField: { - ( + ( self: Lens, key: K, ): Lens - ( + ( key: K, ): (self: Lens) => Lens -} = Function.dual(2, ( +} = Function.dual(2, ( self: Lens, key: K, ): Lens => map( @@ -307,14 +307,14 @@ export declare namespace focusObjectMutableField { * Narrows the focus to a mutable field of an object. Mutates the object in place when written to. */ export const focusObjectMutableField: { - , 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>( +} = Function.dual(2, >( self: Lens, key: K, ): Lens => map(self, a => a[key], (a, b) => { a[key] = b; return a })) @@ -366,14 +366,14 @@ export const focusMutableArrayAt: { * Narrows the focus to an indexed element of a readonly tuple. Replaces the tuple in an immutable fashion when written to. */ export const focusTupleAt: { - ( + ( self: Lens, index: I, ): Lens - ( + ( index: I ): (self: Lens) => Lens -} = Function.dual(2, ( +} = Function.dual(2, ( self: Lens, index: I, ): Lens => map( @@ -386,14 +386,14 @@ export const focusTupleAt: { * Narrows the focus to an indexed element of a mutable tuple. Mutates the tuple in place when written to. */ export const focusMutableTupleAt: { - ( + ( self: Lens, index: I, ): Lens - ( + ( index: I ): (self: Lens) => Lens -} = Function.dual(2, ( +} = Function.dual(2, ( self: Lens, index: I, ): Lens => map( -- 2.49.1 From eb270acce407fdcdd0e3e495e1cf589d538b4cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Mon, 30 Mar 2026 14:11:29 +0200 Subject: [PATCH 3/3] Bump version --- packages/effect-lens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/effect-lens/package.json b/packages/effect-lens/package.json index f5b0f5f..5e3a238 100644 --- a/packages/effect-lens/package.json +++ b/packages/effect-lens/package.json @@ -1,7 +1,7 @@ { "name": "effect-lens", "description": "An effectful Lens type to easily manage nested state", - "version": "0.1.3", + "version": "0.1.4", "type": "module", "files": [ "./README.md", -- 2.49.1