0.1.2 #1
@@ -83,7 +83,7 @@ describe("Lens", () => {
|
|||||||
test("focusTupleAt updates the selected tuple index immutably", async () => {
|
test("focusTupleAt updates the selected tuple index immutably", async () => {
|
||||||
const updated = await Effect.runPromise(
|
const updated = await Effect.runPromise(
|
||||||
Effect.flatMap(
|
Effect.flatMap(
|
||||||
SubscriptionRef.make(["a", "b", "c"] as const),
|
SubscriptionRef.make<readonly [string, string, string]>(["a", "b", "c"]),
|
||||||
parent => {
|
parent => {
|
||||||
const elementLens = Lens.focusTupleAt(Lens.fromSubscriptionRef(parent), 1)
|
const elementLens = Lens.focusTupleAt(Lens.fromSubscriptionRef(parent), 1)
|
||||||
return Effect.flatMap(
|
return Effect.flatMap(
|
||||||
@@ -98,7 +98,7 @@ describe("Lens", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test("focusMutableTupleAt mutates the tuple reference in place", async () => {
|
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(
|
const updated = await Effect.runPromise(
|
||||||
Effect.flatMap(
|
Effect.flatMap(
|
||||||
SubscriptionRef.make(original),
|
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.
|
* Narrows the focus to an indexed element of a readonly tuple. Replaces the tuple in an immutable fashion when written to.
|
||||||
*/
|
*/
|
||||||
export const focusTupleAt: {
|
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>,
|
self: Lens<T, ER, EW, RR, RW>,
|
||||||
index: number,
|
index: I,
|
||||||
): Lens<T[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW>
|
): Lens<T[I], ER, EW, RR, RW>
|
||||||
<T extends readonly [any, ...any[]], ER, EW, RR, RW>(
|
<T extends readonly [any, ...any[]], I extends number, ER, EW, RR, RW>(
|
||||||
index: number
|
index: I
|
||||||
): (self: Lens<T, ER, EW, RR, RW>) => Lens<T[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW>
|
): (self: Lens<T, ER, EW, RR, RW>) => Lens<T[I], ER, EW, RR, RW>
|
||||||
} = Function.dual(2, <T extends readonly [any, ...any[]], 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>,
|
self: Lens<T, ER, EW, RR, RW>,
|
||||||
index: number,
|
index: I,
|
||||||
): Lens<T[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW> => mapEffect(
|
): Lens<T[I], ER, EW, RR, RW> => map(
|
||||||
self,
|
self,
|
||||||
Array.get(index),
|
Array.unsafeGet(index),
|
||||||
(a, b) => Array.replaceOption(a, index, b) as any,
|
(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.
|
* Narrows the focus to an indexed element of a mutable tuple. Mutates the tuple in place when written to.
|
||||||
*/
|
*/
|
||||||
export const focusMutableTupleAt: {
|
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>,
|
self: Lens<T, ER, EW, RR, RW>,
|
||||||
index: number,
|
index: I,
|
||||||
): Lens<T[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW>
|
): Lens<T[I], ER, EW, RR, RW>
|
||||||
<T extends [any, ...any[]], ER, EW, RR, RW>(
|
<T extends [any, ...any[]], I extends number, ER, EW, RR, RW>(
|
||||||
index: number
|
index: I
|
||||||
): (self: Lens<T, ER, EW, RR, RW>) => Lens<T[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW>
|
): (self: Lens<T, ER, EW, RR, RW>) => Lens<T[I], ER, EW, RR, RW>
|
||||||
} = Function.dual(2, <T extends [any, ...any[]], 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>,
|
self: Lens<T, ER, EW, RR, RW>,
|
||||||
index: number,
|
index: I,
|
||||||
): Lens<T[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW> => mapEffect(
|
): Lens<T[I], ER, EW, RR, RW> => map(
|
||||||
self,
|
self,
|
||||||
Array.get(index),
|
Array.unsafeGet(index),
|
||||||
(a, b) => Effect.flatMap(
|
(a, b) => { a[index] = b; return a },
|
||||||
Array.get(a, index),
|
|
||||||
() => Effect.as(Effect.sync(() => { a[index] = b }), a),
|
|
||||||
),
|
|
||||||
))
|
))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user