Quick - ƙ
- Map Over Groups
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
Group elements of the right argument where the corresponding elements in the left argument are equal, then map a link over each group.
Details
Try this out with ¹ƙ
on a few examples to get the hang of it. Essentially, for each index in the right argument, if the element at that index in the left argument is the same as that for another index, the two corresponding elements are grouped together. Groups appear in order of their first occurrence in the right argument, and if the left argument is shorter, the trailing elements are grouped together. Finally, the link is applied to each group.
For example, consider 1,2,1,2,2 Sƙ 1,2,3,4,5,6,7
. Using the left argument as a key, indices [1, 3]
and [2, 4, 5]
(as well as the trailing indices [6, 7]
) should be grouped. Thus, the right argument is grouped into [[1, 3], [2, 4, 5], [6, 7]]
. Finally, S
(Sum) is applied to each group, so the result is [4, 11, 13]
.
Syntax
<monad>ƙ
- a dyadic link that groups the right argument by the left argument as a key, and then applies the monad to each group