Quick - / - Reduce

Characters: /

Tags: array

Arity: monadic

The resulting link is monadic, meaning it takes one argument. Note that the arity refers to that of the resulting link, not the number of links this quick consumes.


Reduce or n-wise reduce a list.


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/ returns [[3, 4, 5], [1, 2, 5], [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 first element, and then for each subsequent element, apply the link to the current accumulator and the incoming value. a,b,c,... ×/ is equivalent to 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.