0.2.5 #43
@@ -1,4 +1,4 @@
|
|||||||
import { Effect, Pipeable, Predicate, Readable, Stream, Subscribable, SubscriptionRef } from "effect"
|
import { Effect, Pipeable, Predicate, Readable, Stream, Subscribable, type SubscriptionRef } from "effect"
|
||||||
import * as Writable from "./Writable.js"
|
import * as Writable from "./Writable.js"
|
||||||
|
|
||||||
|
|
||||||
@@ -24,17 +24,23 @@ export const LensPrototype: LensPrototype = Object.freeze({
|
|||||||
|
|
||||||
export const isLens = (u: unknown): u is Lens<unknown, unknown, unknown, unknown, unknown> => Predicate.hasProperty(u, LensTypeId)
|
export const isLens = (u: unknown): u is Lens<unknown, unknown, unknown, unknown, unknown> => Predicate.hasProperty(u, LensTypeId)
|
||||||
|
|
||||||
export const make = <A, ER, RR, EW, RW>(options: {
|
export const make = <A, ER, RR, EW, RW>(
|
||||||
readonly get: Effect.Effect<A, ER, RR>
|
options: {
|
||||||
readonly changes: Stream.Stream<A, ER, RR>
|
readonly get: Effect.Effect<A, ER, RR>
|
||||||
readonly set: (value: A) => Effect.Effect<void, EW, RW>
|
readonly changes: Stream.Stream<A, ER, RR>
|
||||||
}): Lens<A, ER, RR, EW, RW> => Object.setPrototypeOf({
|
} & (
|
||||||
|
| { readonly modify: <B>(f: (a: A) => readonly [B, A]) => Effect.Effect<B, EW, RW> }
|
||||||
|
| { readonly set: (value: A) => Effect.Effect<void, EW, RW> }
|
||||||
|
)
|
||||||
|
): Lens<A, ER, RR, EW, RW> => Object.setPrototypeOf({
|
||||||
get: options.get,
|
get: options.get,
|
||||||
changes: options.changes,
|
changes: options.changes,
|
||||||
modify: <B>(f: (a: A) => readonly [B, A]) => Effect.flatMap(options.get, a => {
|
modify: Predicate.hasProperty(options, "modify")
|
||||||
const [b, next] = f(a)
|
? options.modify
|
||||||
return Effect.map(options.set(next), () => b)
|
: <B>(f: (a: A) => readonly [B, A]) => Effect.flatMap(options.get, a => {
|
||||||
}),
|
const [b, next] = f(a)
|
||||||
|
return Effect.map(options.set(next), () => b)
|
||||||
|
}),
|
||||||
}, LensPrototype)
|
}, LensPrototype)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,7 +51,7 @@ export const fromSubscriptionRef = <A>(
|
|||||||
): Lens<A, never, never, never, never> => make({
|
): Lens<A, never, never, never, never> => make({
|
||||||
get: ref.get,
|
get: ref.get,
|
||||||
changes: ref.changes,
|
changes: ref.changes,
|
||||||
set: (v: A) => SubscriptionRef.set(ref, v),
|
modify: ref.modify,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const unwrap = <A, ER, RR, EW, RW, E1, R1>(
|
export const unwrap = <A, ER, RR, EW, RW, E1, R1>(
|
||||||
|
|||||||
Reference in New Issue
Block a user