Quick - ƒ
- Reduce With Starting Value
Characters: ƒ
Tags: array
Arity: dyadic
The resulting link is dyadic, meaning it takes two arguments. Note that the arity refers to that of the resulting link, not the number of links this quick consumes.
Functionality
Reduce or n-wise reduce a list starting at the right argument.
Details
If a nilad appears right before ƒ
, this does n-wise reduce. For positive n
, split the list into chunks of length n
(identical to s
(Split (Length))) and reduce each sublist. For negative n
, instead of reducing each sublist, slice and remove chunks of length -n
. For example, 5R ;-2ƒ0
returns [[0, 3, 4, 5], [0, 1, 2, 5], [0, 1, 2, 3, 4]]
- in the first list, [1, 2]
is removed, in the second list, [3, 4]
is removed, and in the last list, [5]
is removed.
To a reduce a list, begin with the right argument, and then for each element, apply the link to the current accumulator and the incoming value. a,b,c,... ׃ y
is equivalent to y × a × b × c × ...
. The link must be a dyad; if you want to apply a monad to the two elements, you can use the idiom ,F¥
for some monad F
, which first pairs the elements and then calls F
on the result.
Syntax
<dyad>ƒ
- reduce<dyad><nilad>ƒ
- n-wise reduce