0.1.2 #1
@@ -1,5 +1,6 @@
|
|||||||
import { Array, Chunk, Effect, Function, Pipeable, Predicate, Readable, Stream, Subscribable, type SubscriptionRef, type SynchronizedRef } from "effect"
|
import { Array, Chunk, Effect, Function, 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"
|
||||||
|
|
||||||
|
|
||||||
export const LensTypeId: unique symbol = Symbol.for("@effect-fc/Lens/Lens")
|
export const LensTypeId: unique symbol = Symbol.for("@effect-fc/Lens/Lens")
|
||||||
@@ -206,7 +207,7 @@ export const mapStream: {
|
|||||||
/**
|
/**
|
||||||
* Narrows the focus to a field of an object. Replaces the object in an immutable fashion when written to.
|
* Narrows the focus to a field of an object. Replaces the object in an immutable fashion when written to.
|
||||||
*/
|
*/
|
||||||
export const focusField: {
|
export const focusObjectField: {
|
||||||
<A extends object, K extends keyof A, ER, EW, RR, RW>(
|
<A extends object, K extends keyof A, ER, EW, RR, RW>(
|
||||||
self: Lens<A, ER, EW, RR, RW>,
|
self: Lens<A, ER, EW, RR, RW>,
|
||||||
key: K,
|
key: K,
|
||||||
@@ -223,7 +224,7 @@ export const focusField: {
|
|||||||
(a, b) => Object.setPrototypeOf({ ...a, [key]: b }, Object.getPrototypeOf(a)),
|
(a, b) => Object.setPrototypeOf({ ...a, [key]: b }, Object.getPrototypeOf(a)),
|
||||||
))
|
))
|
||||||
|
|
||||||
export declare namespace focusMutableField {
|
export declare namespace focusObjectMutableField {
|
||||||
export type WritableKeys<T> = {
|
export type WritableKeys<T> = {
|
||||||
[K in keyof T]-?: IfEquals<
|
[K in keyof T]-?: IfEquals<
|
||||||
{ [P in K]: T[K] },
|
{ [P in K]: T[K] },
|
||||||
@@ -239,15 +240,15 @@ export declare namespace focusMutableField {
|
|||||||
/**
|
/**
|
||||||
* Narrows the focus to a mutable field of an object. Mutates the object in place when written to.
|
* Narrows the focus to a mutable field of an object. Mutates the object in place when written to.
|
||||||
*/
|
*/
|
||||||
export const focusMutableField: {
|
export const focusObjectMutableField: {
|
||||||
<A extends object, K extends focusMutableField.WritableKeys<A>, ER, EW, RR, RW>(
|
<A extends object, K extends focusObjectMutableField.WritableKeys<A>, ER, EW, RR, RW>(
|
||||||
self: Lens<A, ER, EW, RR, RW>,
|
self: Lens<A, ER, EW, RR, RW>,
|
||||||
key: K,
|
key: K,
|
||||||
): Lens<A[K], ER, EW, RR, RW>
|
): Lens<A[K], ER, EW, RR, RW>
|
||||||
<A extends object, K extends focusMutableField.WritableKeys<A>, ER, EW, RR, RW>(
|
<A extends object, K extends focusObjectMutableField.WritableKeys<A>, ER, EW, RR, RW>(
|
||||||
key: K,
|
key: K,
|
||||||
): (self: Lens<A, ER, EW, RR, RW>) => Lens<A[K], ER, EW, RR, RW>
|
): (self: Lens<A, ER, EW, RR, RW>) => Lens<A[K], ER, EW, RR, RW>
|
||||||
} = Function.dual(2, <A extends object, K extends focusMutableField.WritableKeys<A>, ER, EW, RR, RW>(
|
} = Function.dual(2, <A extends object, K extends focusObjectMutableField.WritableKeys<A>, ER, EW, RR, RW>(
|
||||||
self: Lens<A, ER, EW, RR, RW>,
|
self: Lens<A, ER, EW, RR, RW>,
|
||||||
key: K,
|
key: K,
|
||||||
): Lens<A[K], ER, EW, RR, RW> => map(self, a => a[key], (a, b) => { a[key] = b; return a }))
|
): Lens<A[K], ER, EW, RR, RW> => map(self, a => a[key], (a, b) => { a[key] = b; return a }))
|
||||||
@@ -259,7 +260,7 @@ export const focusArrayAt: {
|
|||||||
<A extends readonly any[], ER, EW, RR, RW>(
|
<A extends readonly any[], ER, EW, RR, RW>(
|
||||||
self: Lens<A, ER, EW, RR, RW>,
|
self: Lens<A, ER, EW, RR, RW>,
|
||||||
index: number,
|
index: number,
|
||||||
): Lens<A[number]>
|
): Lens<A[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW>
|
||||||
<A extends readonly any[], ER, EW, RR, RW>(
|
<A extends readonly any[], ER, EW, RR, RW>(
|
||||||
index: number
|
index: number
|
||||||
): (self: Lens<A, ER, EW, RR, RW>) => Lens<A[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW>
|
): (self: Lens<A, ER, EW, RR, RW>) => Lens<A[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW>
|
||||||
|
|||||||
53
packages/effect-lens/src/Subscribable.ts
Normal file
53
packages/effect-lens/src/Subscribable.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import { Array, Chunk, Function, Subscribable } from "effect"
|
||||||
|
import type { NoSuchElementException } from "effect/Cause"
|
||||||
|
|
||||||
|
|
||||||
|
export * from "effect/Subscribable"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Narrows the focus to a field of an object.
|
||||||
|
*/
|
||||||
|
export const focusObjectField: {
|
||||||
|
<A extends object, K extends keyof A, E, R>(
|
||||||
|
self: Subscribable.Subscribable<A, E, R>,
|
||||||
|
key: K,
|
||||||
|
): Subscribable.Subscribable<A[K], E, R>
|
||||||
|
<A extends object, K extends keyof A, E, R>(
|
||||||
|
key: K,
|
||||||
|
): (self: Subscribable.Subscribable<A, E, R>) => Subscribable.Subscribable<A[K], E, R>
|
||||||
|
} = Function.dual(2, <A extends object, K extends keyof A, E, R>(
|
||||||
|
self: Subscribable.Subscribable<A, E, R>,
|
||||||
|
key: K,
|
||||||
|
): Subscribable.Subscribable<A[K], E, R> => Subscribable.map(self, a => a[key]))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Narrows the focus to an indexed element of an array.
|
||||||
|
*/
|
||||||
|
export const focusArrayAt: {
|
||||||
|
<A extends readonly any[], E, R>(
|
||||||
|
self: Subscribable.Subscribable<A, E, R>,
|
||||||
|
index: number,
|
||||||
|
): Subscribable.Subscribable<A[number], E, R>
|
||||||
|
<A extends readonly any[], E, R>(
|
||||||
|
index: number
|
||||||
|
): (self: Subscribable.Subscribable<A, E, R>) => Subscribable.Subscribable<A[number], E | NoSuchElementException, R>
|
||||||
|
} = Function.dual(2, <A extends readonly any[], E, R>(
|
||||||
|
self: Subscribable.Subscribable<A, E, R>,
|
||||||
|
index: number,
|
||||||
|
): Subscribable.Subscribable<A[number], E | NoSuchElementException, R> => Subscribable.mapEffect(self, Array.get(index)))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Narrows the focus to an indexed element of `Chunk`.
|
||||||
|
*/
|
||||||
|
export const focusChunkAt: {
|
||||||
|
<A, E, R>(
|
||||||
|
self: Subscribable.Subscribable<Chunk.Chunk<A>, E, R>,
|
||||||
|
index: number,
|
||||||
|
): Subscribable.Subscribable<A, E | NoSuchElementException, R>
|
||||||
|
<A, E, R>(
|
||||||
|
index: number
|
||||||
|
): (self: Subscribable.Subscribable<Chunk.Chunk<A>, E, R>) => Subscribable.Subscribable<A, E | NoSuchElementException, R>
|
||||||
|
} = Function.dual(2, <A, E, R>(
|
||||||
|
self: Subscribable.Subscribable<Chunk.Chunk<A>, E, R>,
|
||||||
|
index: number,
|
||||||
|
): Subscribable.Subscribable<A, E | NoSuchElementException, R> => Subscribable.mapEffect(self, Chunk.get(index)))
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
export * as Lens from "./Lens.js"
|
export * as Lens from "./Lens.js"
|
||||||
export * as PropertyPath from "./PropertyPath.js"
|
export * as PropertyPath from "./PropertyPath.js"
|
||||||
|
export * as Subscribable from "./Subscribable.js"
|
||||||
|
|||||||
Reference in New Issue
Block a user