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

This commit is contained in:
Julien Valverdé
2026-03-27 13:48:45 +01:00
parent b2cf51c393
commit d2e4875b8a
2 changed files with 24 additions and 27 deletions

View File

@@ -83,7 +83,7 @@ describe("Lens", () => {
test("focusTupleAt updates the selected tuple index immutably", async () => {
const updated = await Effect.runPromise(
Effect.flatMap(
SubscriptionRef.make(["a", "b", "c"] as const),
SubscriptionRef.make<readonly [string, string, string]>(["a", "b", "c"]),
parent => {
const elementLens = Lens.focusTupleAt(Lens.fromSubscriptionRef(parent), 1)
return Effect.flatMap(
@@ -98,7 +98,7 @@ describe("Lens", () => {
})
test("focusMutableTupleAt mutates the tuple reference in place", async () => {
const original = ["foo", "bar"] as ["foo", "bar"]
const original: [string, string] = ["foo", "bar"]
const updated = await Effect.runPromise(
Effect.flatMap(
SubscriptionRef.make(original),

View File

@@ -300,43 +300,40 @@ 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[]], ER, EW, RR, RW>(
<T extends readonly [any, ...any[]], I extends number, ER, EW, RR, RW>(
self: Lens<T, ER, EW, RR, RW>,
index: number,
): Lens<T[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW>
<T extends readonly [any, ...any[]], ER, EW, RR, RW>(
index: number
): (self: Lens<T, ER, EW, RR, RW>) => Lens<T[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW>
} = Function.dual(2, <T extends readonly [any, ...any[]], 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>(
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>(
self: Lens<T, ER, EW, RR, RW>,
index: number,
): Lens<T[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW> => mapEffect(
index: I,
): Lens<T[I], ER, EW, RR, RW> => map(
self,
Array.get(index),
(a, b) => Array.replaceOption(a, index, b) as any,
Array.unsafeGet(index),
(a, b) => Array.replace(a, index, b) as any,
))
/**
* 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[]], ER, EW, RR, RW>(
<T extends [any, ...any[]], I extends number, ER, EW, RR, RW>(
self: Lens<T, ER, EW, RR, RW>,
index: number,
): Lens<T[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW>
<T extends [any, ...any[]], ER, EW, RR, RW>(
index: number
): (self: Lens<T, ER, EW, RR, RW>) => Lens<T[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW>
} = Function.dual(2, <T extends [any, ...any[]], ER, EW, RR, RW>(
index: I,
): Lens<T[I], ER, EW, RR, RW>
<T extends [any, ...any[]], I extends number, ER, EW, RR, RW>(
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>(
self: Lens<T, ER, EW, RR, RW>,
index: number,
): Lens<T[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW> => mapEffect(
index: I,
): Lens<T[I], ER, EW, RR, RW> => map(
self,
Array.get(index),
(a, b) => Effect.flatMap(
Array.get(a, index),
() => Effect.as(Effect.sync(() => { a[index] = b }), a),
),
Array.unsafeGet(index),
(a, b) => { a[index] = b; return a },
))
/**