0.1.3 #2
@@ -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 * 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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user