Skip to main content

.map(): Optic

ts
Optic<A extends any[]>.map: () => Optic<A[number], mapped>;
ts
Optic<A extends any[]>.map: () => Optic<A[number], mapped>;

This method returns a new mapped optic from an optic focused on an array.

Example:

ts
const numbersOptic = createState([1, 2, 3, 4, 5]);
 
const numbersMappedOptic = numbersOptic.map();
const numbersMappedOptic: Optic<number, mapped>
 
numbersMappedOptic.set((prev) => prev * 2);
 
numbersMappedOptic.get(); // [2, 4, 6, 8, 10]
ts
const numbersOptic = createState([1, 2, 3, 4, 5]);
 
const numbersMappedOptic = numbersOptic.map();
const numbersMappedOptic: Optic<number, mapped>
 
numbersMappedOptic.set((prev) => prev * 2);
 
numbersMappedOptic.get(); // [2, 4, 6, 8, 10]