filter

From The K Language Wiki
Revision as of 08:01, 20 July 2021 by Razetime (talk | contribs) (add filter primitive page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Filter
f#y
f_y
Supported in K6-K9

Filter and filter-out are used to filter elements from an array using a monadic(single-argument) function f.

For filter(#), the elements which return truthy values when passed through f are left in the array. For filter-out(_), the elements returning falsy values are kept.

Note that filters are verbs and hence cannot take a primitive as argument. f must be a defined function or a train.

 (2!)#!8
1 3 5 7

 (2!)_!8
0 2 4 6