0.1.3 #2

Merged
Thilawyn merged 4 commits from next into master 2026-03-28 21:13:30 +01:00
Showing only changes of commit 2328e1fc3d - Show all commits

View File

@@ -1,4 +1,4 @@
import { Array, Chunk, Effect, Function, Pipeable, Predicate, Readable, Stream, type SubscriptionRef, type SynchronizedRef } from "effect" import { Array, Chunk, Effect, Function, Option, Pipeable, Predicate, Readable, Stream, type SubscriptionRef, type SynchronizedRef } from "effect"
import type { NoSuchElementException } from "effect/Cause" import type { NoSuchElementException } from "effect/Cause"
import * as Subscribable from "./Subscribable.js" import * as Subscribable from "./Subscribable.js"
@@ -183,6 +183,36 @@ export const mapEffect: {
)), )),
})) }))
/**
* Derives a new `Lens` by applying synchronous getters and setters over the value inside an `Option`.
*
* Similar to `Option.map`, this preserves the `Option` structure:
* - If the `Option` is `Some(a)`, applies the getter and setter to the inner value
* - If the `Option` is `None`, it remains `None`
*/
export const mapOption: {
<A, ER, EW, RR, RW, B>(
self: Lens<Option.Option<A>, ER, EW, RR, RW>,
get: (a: NoInfer<A>) => B,
set: (a: NoInfer<A>, b: B) => NoInfer<A>,
): Lens<Option.Option<B>, ER, EW, RR, RW>
<A, ER, EW, RR, RW, B>(
get: (a: NoInfer<A>) => B,
set: (a: NoInfer<A>, b: B) => NoInfer<A>,
): (self: Lens<Option.Option<A>, ER, EW, RR, RW>) => Lens<Option.Option<B>, ER, EW, RR, RW>
} = Function.dual(3, <A, ER, EW, RR, RW, B>(
self: Lens<Option.Option<A>, ER, EW, RR, RW>,
get: (a: NoInfer<A>) => B,
set: (a: NoInfer<A>, b: B) => NoInfer<A>,
): Lens<Option.Option<B>, ER, EW, RR, RW> => map(
self,
Option.map(get),
(opt, newOpt) => Option.match(opt, {
onSome: a => Option.map(newOpt, b => set(a, b)),
onNone: () => Option.none(),
}),
))
/** /**
* Allows transforming only the `changes` stream of a `Lens` while keeping the focus type intact. * Allows transforming only the `changes` stream of a `Lens` while keeping the focus type intact.
*/ */