diff --git a/packages/effect-fc/src/Lens.ts b/packages/effect-fc/src/Lens.ts index 1b2f19a..6f12cdc 100644 --- a/packages/effect-fc/src/Lens.ts +++ b/packages/effect-fc/src/Lens.ts @@ -5,6 +5,9 @@ import type { NoSuchElementException } from "effect/Cause" export const LensTypeId: unique symbol = Symbol.for("@effect-fc/Lens/Lens") export type LensTypeId = typeof LensTypeId +/** + * Read/write view over a value that exposes the latest value and a stream of updates. + */ export interface Lens extends Subscribable.Subscribable { readonly [LensTypeId]: LensTypeId @@ -14,6 +17,9 @@ extends Subscribable.Subscribable { ) => Effect.Effect } +/** + * Internal `Lens` implementation. + */ export class LensImpl extends Pipeable.Class() implements Lens { readonly [Readable.TypeId]: Readable.TypeId = Readable.TypeId @@ -32,9 +38,15 @@ export class LensImpl => Predicate.hasProperty(u, LensTypeId) +/** + * Builds a `Lens` instance when you supply how to read the current value, observe changes, and apply transformations. + */ export const make = ( options: { readonly get: Effect.Effect @@ -61,7 +73,7 @@ export const make = ( ) /** - * Creates a `Lens` that directly proxies a `SubscriptionRef`. + * Creates a `Lens` that proxies a `SubscriptionRef`. */ export const fromSubscriptionRef = ( ref: SubscriptionRef.SubscriptionRef @@ -73,6 +85,9 @@ export const fromSubscriptionRef = ( ) => ref.modifyEffect(f), }) +/** + * Flattens an effectful `Lens`. + */ export const unwrap = ( effect: Effect.Effect, E1, R1> ): Lens => make({ @@ -84,6 +99,9 @@ export const unwrap = ( }) +/** + * Derives a new `Lens` by applying synchronous getters and setters over the focused value. + */ export const map: { ( self: Lens, @@ -108,6 +126,9 @@ export const map: { ), })) +/** + * Derives a new `Lens` by applying effectful getters and setters over the focused value. + */ export const mapEffect: { ( self: Lens, @@ -139,6 +160,9 @@ export const mapEffect: { )), })) +/** + * Allows transforming only the `changes` stream of a `Lens` while keeping the focus type intact. + */ export const mapStream: { ( self: Lens, @@ -157,6 +181,9 @@ export const mapStream: { })) +/** + * Narrows the focus to a field of an object. Replaces the object in an immutable fashion when written to. + */ export const focusField: { ( self: Lens, @@ -187,6 +214,9 @@ export declare namespace focusMutableField { type IfEquals = (() => T extends X ? 1 : 2) extends (() => T extends Y ? 1 : 2) ? A : B } +/** + * Narrows the focus to a mutable field of an object. Mutates the object in place when written to. + */ export const focusMutableField: { , ER, EW, RR, RW>( self: Lens, @@ -200,6 +230,9 @@ export const focusMutableField: { key: K, ): Lens => map(self, a => a[key], (a, b) => { a[key] = b; return a })) +/** + * Narrows the focus to an indexed element of an array. Replaces the array in an immutable fashion when written to. + */ export const focusArrayAt: { ( self: Lens, @@ -217,6 +250,9 @@ export const focusArrayAt: { (a, b) => Array.replaceOption(a, index, b) as any, )) +/** + * Narrows the focus to an indexed element of a mutable array. Mutates the array in place when written to. + */ export const focusMutableArrayAt: { ( self: Lens, @@ -237,6 +273,9 @@ export const focusMutableArrayAt: { ), )) +/** + * Narrows the focus to an indexed element of `Chunk`. Replaces the `Chunk` in an immutable fashion when written to. + */ export const focusChunkAt: { ( self: Lens, ER, EW, RR, RW>,