fold

From The K Language Wiki
Revision as of 06:08, 26 July 2021 by Razetime (talk | contribs) (add fold page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Fold
f/y
x f/y

Fold, also known as reduce, foldl and over, takes a dyadic function f and reduces an array y using it.

Fold is a very strong utility. For example, you can sum a list using +/.

 +/1 2 3 4
10
 ,/("ab";1;`d`a`b)
("a"
 "b"
 1
 `d
 `a
 `b)

Specifying a left argument x uses it as an initial value.

 3 +/1 2 3 4
13