Fix
All checks were successful
Lint / lint (push) Successful in 13s

This commit is contained in:
Julien Valverdé
2026-03-23 03:59:36 +01:00
parent 45c854a8d0
commit 821ba95247
2 changed files with 20 additions and 15 deletions

View File

@@ -5,7 +5,7 @@ import * as Writable from "./Writable.js"
export const LensTypeId: unique symbol = Symbol.for("@effect-fc/Lens/Lens") export const LensTypeId: unique symbol = Symbol.for("@effect-fc/Lens/Lens")
export type LensTypeId = typeof LensTypeId export type LensTypeId = typeof LensTypeId
export interface Lens<in out A, ER = unknown, RR = unknown, EW = unknown, RW = unknown> export interface Lens<in out A, ER = never, RR = never, EW = never, RW = never>
extends LensPrototype, Subscribable.Subscribable<A, ER, RR>, Writable.Writable<A, EW, RW> {} extends LensPrototype, Subscribable.Subscribable<A, ER, RR>, Writable.Writable<A, EW, RW> {}
@@ -29,7 +29,7 @@ export const make = <A, ER, RR, EW, RW>(
readonly get: Effect.Effect<A, ER, RR> readonly get: Effect.Effect<A, ER, RR>
readonly changes: Stream.Stream<A, ER, RR> readonly changes: Stream.Stream<A, ER, RR>
} & ( } & (
| { readonly modify: <B>(f: (a: A) => readonly [B, A]) => Effect.Effect<B, EW, RW> } | { readonly modify: <B, E1 = never, R1 = never>(f: (a: A) => Effect.Effect<readonly [B, A], E1, R1>) => Effect.Effect<B, EW | E1, RW | R1> }
| { readonly set: (value: A) => Effect.Effect<void, EW, RW> } | { readonly set: (value: A) => Effect.Effect<void, EW, RW> }
) )
): Lens<A, ER, RR, EW, RW> => Object.setPrototypeOf({ ): Lens<A, ER, RR, EW, RW> => Object.setPrototypeOf({
@@ -37,10 +37,11 @@ export const make = <A, ER, RR, EW, RW>(
changes: options.changes, changes: options.changes,
modify: Predicate.hasProperty(options, "modify") modify: Predicate.hasProperty(options, "modify")
? options.modify ? options.modify
: <B>(f: (a: A) => readonly [B, A]) => Effect.flatMap(options.get, a => { : <B, E1 = never, R1 = never>(f: (a: A) => Effect.Effect<readonly [B, A], E1, R1>) =>
const [b, next] = f(a) Effect.flatMap(options.get, a =>
return Effect.map(options.set(next), () => b) Effect.flatMap(f(a), ([b, next]) => Effect.map(options.set(next), () => b)
}), )
),
}, LensPrototype) }, LensPrototype)
/** /**
@@ -51,13 +52,15 @@ 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,
modify: ref.modify, modify: ref.modifyEffect,
}) })
export const unwrap = <A, ER, RR, EW, RW, E1, R1>( export const unwrap = <A, ER, RR, EW, RW, E1, R1>(
effect: Effect.Effect<Lens<A, ER, RR, EW, RW>, E1, R1> effect: Effect.Effect<Lens<A, ER, RR, EW, RW>, E1, R1>
): Lens<A, ER | E1, RR | R1, EW | E1, RW | R1> => make({ ): Lens<A, ER | E1, RR | R1, EW | E1, RW | R1> => make({
get: Effect.flatMap(effect, p => p.get), get: Effect.flatMap(effect, l => l.get),
changes: Stream.unwrap(Effect.map(effect, p => p.changes)), changes: Stream.unwrap(Effect.map(effect, l => l.changes)),
set: (v: A) => Effect.flatMap(effect, p => p.modify(() => [undefined as void as any, v]) as any), modify: <B, E2 = never, R2 = never>(
f: (a: A) => Effect.Effect<readonly [B, A], E2, R2>
) => Effect.flatMap(effect, l => l.modify(f)),
}) })

View File

@@ -5,7 +5,7 @@ export const WritableTypeId: unique symbol = Symbol.for("@effect-fc/Writable/Wri
export type WritableTypeId = typeof WritableTypeId export type WritableTypeId = typeof WritableTypeId
export interface Writable<in out A, E = never, R = never> extends WritablePrototype { export interface Writable<in out A, E = never, R = never> extends WritablePrototype {
readonly modify: <B>(f: (a: A) => readonly [B, A]) => Effect.Effect<B, E, R> readonly modify: <B, E1 = never, R1 = never>(f: (a: A) => Effect.Effect<readonly [B, A], E1, R1>) => Effect.Effect<B, E | E1, R | R1>
} }
@@ -25,7 +25,7 @@ export const isWritable = (u: unknown): u is Writable<unknown, unknown, unknown>
* Construct a `Writable` from a `modify` function. * Construct a `Writable` from a `modify` function.
*/ */
export const make = <A, E, R>( export const make = <A, E, R>(
modify: <B>(f: (a: A) => readonly [B, A]) => Effect.Effect<B, E, R> modify: <B, E1 = never, R1 = never>(f: (a: A) => Effect.Effect<readonly [B, A], E1, R1>) => Effect.Effect<B, E | E1, R | R1>,
): Writable<A, E, R> => Object.setPrototypeOf({ modify }, WritablePrototype) ): Writable<A, E, R> => Object.setPrototypeOf({ modify }, WritablePrototype)
/** /**
@@ -33,6 +33,8 @@ export const make = <A, E, R>(
*/ */
export const unwrap = <A, E, R, E1, R1>( export const unwrap = <A, E, R, E1, R1>(
effect: Effect.Effect<Writable<A, E, R>, E1, R1> effect: Effect.Effect<Writable<A, E, R>, E1, R1>
): Writable<A, E | E1, R | R1> => make(<B>( ): Writable<A, E | E1, R | R1> => make(
f: (a: A) => readonly [B, A] <B, E2 = never, R2 = never>(
) => Effect.flatMap(effect, w => w.modify(f))) f: (a: A) => Effect.Effect<readonly [B, A], E2, R2>
) => Effect.flatMap(effect, w => w.modify(f))
)