<
const T extends ReadonlyArray<unknown>,
const I extends ReadonlyArray<Indices<T>>,
L extends Lambda
>(
indices: I,
lambda: L
): (self: T) => {
[K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]
}
<
const T extends ReadonlyArray<unknown>,
const I extends ReadonlyArray<Indices<T>>,
L extends Lambda
>(
self: T,
indices: I,
lambda: L
): { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K] }Applies a Struct.Lambda transformation only to the elements at the
specified indices; all other elements are copied unchanged.
When to use
Use when you want to apply the same transformation to a subset of positions.
Example (Wrapping only selected elements in arrays)
import { pipe, Struct, Tuple } from "effect"
interface AsArray extends Struct.Lambda {
<A>(self: A): Array<A>
readonly "~lambda.out": Array<this["~lambda.in"]>
}
const asArray = Struct.lambda<AsArray>((a) => [a])
const result = pipe(
Tuple.make(1, "hello", true),
Tuple.mapPick([0, 2], asArray)
)
console.log(result) // [[1], "hello", [true]]Source effect/Tuple.ts:43823 lines
export const const mapPick: {
<
T extends ReadonlyArray<unknown>,
I extends ReadonlyArray<Indices<T>>,
L extends Lambda
>(
indices: I,
lambda: L
): (self: T) => {
[K in keyof T]: K extends `${I[number]}`
? Apply<L, T[K]>
: T[K]
}
<
T extends ReadonlyArray<unknown>,
I extends ReadonlyArray<Indices<T>>,
L extends Lambda
>(
self: T,
indices: I,
lambda: L
): {
[K in keyof T]: K extends `${I[number]}`
? Apply<L, T[K]>
: T[K]
}
}
Applies a Struct.Lambda transformation only to the elements at the
specified indices; all other elements are copied unchanged.
When to use
Use when you want to apply the same transformation to a subset of
positions.
Example (Wrapping only selected elements in arrays)
import { pipe, Struct, Tuple } from "effect"
interface AsArray extends Struct.Lambda {
<A>(self: A): Array<A>
readonly "~lambda.out": Array<this["~lambda.in"]>
}
const asArray = Struct.lambda<AsArray>((a) => [a])
const result = pipe(
Tuple.make(1, "hello", true),
Tuple.mapPick([0, 2], asArray)
)
console.log(result) // [[1], "hello", [true]]
mapPick: {
<const function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(indices: I, lambda: L): (self: T) => { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }T extends interface ReadonlyArray<T>ReadonlyArray<unknown>, const function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(indices: I, lambda: L): (self: T) => { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }I extends interface ReadonlyArray<T>ReadonlyArray<type Indices<
T extends ReadonlyArray<unknown>
> = Partial<T>["length"] extends T["length"]
? never
: Partial<T>["length"]
Indices<function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(indices: I, lambda: L): (self: T) => { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }T>>, function (type parameter) L in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(indices: I, lambda: L): (self: T) => { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }L extends import LambdaLambda>(
indices: const I extends ReadonlyArray<Indices<T>>indices: function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(indices: I, lambda: L): (self: T) => { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }I,
lambda: L extends Lambdalambda: function (type parameter) L in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(indices: I, lambda: L): (self: T) => { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }L
): (
self: const T extends ReadonlyArray<unknown>self: function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(indices: I, lambda: L): (self: T) => { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }T
) => { [function (type parameter) KK in keyof function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(indices: I, lambda: L): (self: T) => { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }T]: function (type parameter) KK extends `${function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(indices: I, lambda: L): (self: T) => { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }I[number]}` ? import ApplyApply<function (type parameter) L in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(indices: I, lambda: L): (self: T) => { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }L, function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(indices: I, lambda: L): (self: T) => { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }T[function (type parameter) KK]> : function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(indices: I, lambda: L): (self: T) => { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }T[function (type parameter) KK] }
<const function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(self: T, indices: I, lambda: L): { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }T extends interface ReadonlyArray<T>ReadonlyArray<unknown>, const function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(self: T, indices: I, lambda: L): { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }I extends interface ReadonlyArray<T>ReadonlyArray<type Indices<
T extends ReadonlyArray<unknown>
> = Partial<T>["length"] extends T["length"]
? never
: Partial<T>["length"]
Indices<function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(self: T, indices: I, lambda: L): { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }T>>, function (type parameter) L in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(self: T, indices: I, lambda: L): { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }L extends import LambdaLambda>(
self: const T extends ReadonlyArray<unknown>self: function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(self: T, indices: I, lambda: L): { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }T,
indices: const I extends ReadonlyArray<Indices<T>>indices: function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(self: T, indices: I, lambda: L): { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }I,
lambda: L extends Lambdalambda: function (type parameter) L in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(self: T, indices: I, lambda: L): { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }L
): { [function (type parameter) KK in keyof function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(self: T, indices: I, lambda: L): { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }T]: function (type parameter) KK extends `${function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(self: T, indices: I, lambda: L): { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }I[number]}` ? import ApplyApply<function (type parameter) L in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(self: T, indices: I, lambda: L): { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }L, function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(self: T, indices: I, lambda: L): { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }T[function (type parameter) KK]> : function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(self: T, indices: I, lambda: L): { [K in keyof T]: K extends `${I[number]}` ? Apply<L, T[K]> : T[K]; }T[function (type parameter) KK] }
} = import dualdual(
3,
<const function (type parameter) T in <const T extends ReadonlyArray<unknown>, L extends Function>(self: T, indices: ReadonlyArray<number>, lambda: L): any[]T extends interface ReadonlyArray<T>ReadonlyArray<unknown>, function (type parameter) L in <const T extends ReadonlyArray<unknown>, L extends Function>(self: T, indices: ReadonlyArray<number>, lambda: L): any[]L extends Function>(
self: const T extends ReadonlyArray<unknown>self: function (type parameter) T in <const T extends ReadonlyArray<unknown>, L extends Function>(self: T, indices: ReadonlyArray<number>, lambda: L): any[]T,
indices: readonly number[]indices: interface ReadonlyArray<T>ReadonlyArray<number>,
lambda: L extends Functionlambda: function (type parameter) L in <const T extends ReadonlyArray<unknown>, L extends Function>(self: T, indices: ReadonlyArray<number>, lambda: L): any[]L
) => {
const const toPick: Set<number>toPick = new var Set: SetConstructor
new <number>(iterable?: Iterable<number> | null | undefined) => Set<number> (+1 overload)
Set<number>(indices: readonly number[]indices)
return self: const T extends ReadonlyArray<unknown>self.ReadonlyArray<unknown>.map<any>(callbackfn: (value: unknown, index: number, array: readonly unknown[]) => any, thisArg?: any): any[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((e: unknowne, i: numberi) => (const toPick: Set<number>toPick.Set<number>.has(value: number): booleanhas(i: numberi) ? lambda: L extends Functionlambda(e: unknowne) : e: unknowne))
}
)