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

This commit is contained in:
Julien Valverdé
2026-03-23 03:03:35 +01:00
parent 54b05ed8da
commit 45c854a8d0

View File

@@ -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,14 +24,20 @@ 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>(
options: {
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 set: (value: A) => Effect.Effect<void, EW, RW> } & (
}): 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")
? options.modify
: <B>(f: (a: A) => readonly [B, A]) => Effect.flatMap(options.get, a => {
const [b, next] = f(a) const [b, next] = f(a)
return Effect.map(options.set(next), () => b) return Effect.map(options.set(next), () => b)
}), }),
@@ -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>(