0.1.4 #3
@@ -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",
|
||||
|
||||
@@ -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: {
|
||||
<A extends object, K extends keyof A, ER, EW, RR, RW>(
|
||||
<A extends object, ER, EW, RR, RW, K extends keyof A>(
|
||||
self: Lens<A, ER, EW, RR, RW>,
|
||||
key: K,
|
||||
): Lens<A[K], ER, EW, RR, RW>
|
||||
<A extends object, K extends keyof A, ER, EW, RR, RW>(
|
||||
<A extends object, ER, EW, RR, RW, K extends keyof A>(
|
||||
key: K,
|
||||
): (self: Lens<A, ER, EW, RR, RW>) => Lens<A[K], ER, EW, RR, RW>
|
||||
} = Function.dual(2, <A extends object, K extends keyof A, ER, EW, RR, RW>(
|
||||
} = Function.dual(2, <A extends object, ER, EW, RR, RW, K extends keyof A>(
|
||||
self: Lens<A, ER, EW, RR, RW>,
|
||||
key: K,
|
||||
): Lens<A[K], ER, EW, RR, RW> => 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: {
|
||||
<A extends object, K extends focusObjectMutableField.WritableKeys<A>, ER, EW, RR, RW>(
|
||||
<A extends object, ER, EW, RR, RW, K extends focusObjectMutableField.WritableKeys<A>>(
|
||||
self: Lens<A, ER, EW, RR, RW>,
|
||||
key: K,
|
||||
): Lens<A[K], ER, EW, RR, RW>
|
||||
<A extends object, K extends focusObjectMutableField.WritableKeys<A>, ER, EW, RR, RW>(
|
||||
<A extends object, ER, EW, RR, RW, K extends focusObjectMutableField.WritableKeys<A>>(
|
||||
key: K,
|
||||
): (self: Lens<A, ER, EW, RR, RW>) => Lens<A[K], ER, EW, RR, RW>
|
||||
} = Function.dual(2, <A extends object, K extends focusObjectMutableField.WritableKeys<A>, ER, EW, RR, RW>(
|
||||
} = Function.dual(2, <A extends object, ER, EW, RR, RW, K extends focusObjectMutableField.WritableKeys<A>>(
|
||||
self: Lens<A, ER, EW, RR, RW>,
|
||||
key: K,
|
||||
): Lens<A[K], ER, EW, RR, RW> => 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: {
|
||||
<T extends readonly [any, ...any[]], I extends number, ER, EW, RR, RW>(
|
||||
<T extends readonly [any, ...any[]], ER, EW, RR, RW, I extends number>(
|
||||
self: Lens<T, ER, EW, RR, RW>,
|
||||
index: I,
|
||||
): Lens<T[I], ER, EW, RR, RW>
|
||||
<T extends readonly [any, ...any[]], I extends number, ER, EW, RR, RW>(
|
||||
<T extends readonly [any, ...any[]], ER, EW, RR, RW, I extends number>(
|
||||
index: I
|
||||
): (self: Lens<T, ER, EW, RR, RW>) => Lens<T[I], ER, EW, RR, RW>
|
||||
} = Function.dual(2, <T extends readonly [any, ...any[]], I extends number, ER, EW, RR, RW>(
|
||||
} = Function.dual(2, <T extends readonly [any, ...any[]], ER, EW, RR, RW, I extends number>(
|
||||
self: Lens<T, ER, EW, RR, RW>,
|
||||
index: I,
|
||||
): Lens<T[I], ER, EW, RR, RW> => 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: {
|
||||
<T extends [any, ...any[]], I extends number, ER, EW, RR, RW>(
|
||||
<T extends [any, ...any[]], ER, EW, RR, RW, I extends number>(
|
||||
self: Lens<T, ER, EW, RR, RW>,
|
||||
index: I,
|
||||
): Lens<T[I], ER, EW, RR, RW>
|
||||
<T extends [any, ...any[]], I extends number, ER, EW, RR, RW>(
|
||||
<T extends [any, ...any[]], ER, EW, RR, RW, I extends number>(
|
||||
index: I
|
||||
): (self: Lens<T, ER, EW, RR, RW>) => Lens<T[I], ER, EW, RR, RW>
|
||||
} = Function.dual(2, <T extends [any, ...any[]], I extends number, ER, EW, RR, RW>(
|
||||
} = Function.dual(2, <T extends [any, ...any[]], ER, EW, RR, RW, I extends number>(
|
||||
self: Lens<T, ER, EW, RR, RW>,
|
||||
index: I,
|
||||
): Lens<T[I], ER, EW, RR, RW> => map(
|
||||
|
||||
@@ -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: {
|
||||
<A, B, E, R>(
|
||||
self: Subscribable.Subscribable<Option.Option<A>, E, R>,
|
||||
f: (a: A) => B,
|
||||
): Subscribable.Subscribable<Option.Option<B>, E, R>
|
||||
<A, B>(
|
||||
f: (a: A) => B,
|
||||
): <E, R>(self: Subscribable.Subscribable<Option.Option<A>, E, R>) => Subscribable.Subscribable<Option.Option<B>, E, R>
|
||||
} = Function.dual(2, <A, B, E, R>(
|
||||
self: Subscribable.Subscribable<Option.Option<A>, E, R>,
|
||||
f: (a: A) => B,
|
||||
): Subscribable.Subscribable<Option.Option<B>, E, R> => Subscribable.map(self, Option.map(f)))
|
||||
|
||||
/**
|
||||
* Maps over an `Option` value in the `Subscribable` with an Effect.
|
||||
*/
|
||||
export const mapOptionEffect: {
|
||||
<A, B, E, E2, R>(
|
||||
self: Subscribable.Subscribable<Option.Option<A>, E, R>,
|
||||
f: (a: A) => Effect.Effect<B, E2, R>,
|
||||
): Subscribable.Subscribable<Option.Option<B>, E | E2, R>
|
||||
<A, B, E2>(
|
||||
f: (a: A) => Effect.Effect<B, E2>,
|
||||
): <E, R>(self: Subscribable.Subscribable<Option.Option<A>, E, R>) => Subscribable.Subscribable<Option.Option<B>, E | E2, R>
|
||||
} = Function.dual(2, <A, B, E, E2, R>(
|
||||
self: Subscribable.Subscribable<Option.Option<A>, E, R>,
|
||||
f: (a: A) => Effect.Effect<B, E2, R>,
|
||||
): Subscribable.Subscribable<Option.Option<B>, 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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user