@@ -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),
|
||||
|
||||
@@ -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 },
|
||||
))
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user