Quick - ¦ - Apply At Indices

Characters: ¦

Tags: array , number

Arity: depends

The resulting link's arity depends on the consumed links, but will be of fixed arity when returned. This is different from variadic links, whose arity can change or be coerced by context or other quicks. Note that the arity refers to that of the resulting link, not the number of links this quick consumes.

Functionality

Apply a link to the specified indices. This description is actually misleading - read the description for more details on how it works exactly.

Details

This does not actually just apply a link to elements at specific indices of a list. Rather, it first applies the link to the list itself. Then, it merges the original and the resulting list together - at each index of the original list, if it is in the set of indices to apply to, it selects the resulting value, and otherwise, it selects the original value. The result list is repeated as many times as necessary. If you need to apply a non-vectorizing link to specific elements, like taking the length of the first and third item, use (Each).

Consider the following example: 1,3,2,1,3,2,3,2 M 2,3,5 ¦. Firstly, we evaluate M (Indices of Maximal Elements) on [1, 3, 2, 1, 3, 2, 3, 2]. This returns [2, 5, 7]. Then, we repeat the result list, line up the elements, and select the resulting element for indices 2, 3, 5 and the original element everywhere else:

[1, 3, 2, 1, 3, 2, 3, 2]
[2, 5, 7, 2, 5, 7, 2, 5]
 ↓  ↓  ↓  ↓  ↓  ↓  ↓  ↓
 1 [2][3] 4 [5] 6  7  8
 ↓  ↓  ↓  ↓  ↓  ↓  ↓  ↓
[1, 5, 7, 1, 5, 2, 3, 2]

(Try It Online!)

Syntax