Catamorphism: Difference between revisions
Content added Content deleted
m (→{{header|RPL}}: formatted code, comment on STREAM function) |
m (→{{header|Zig}}: fix comment in code) |
||
Line 2,980: | Line 2,980: | ||
===Reduce a slice=== |
===Reduce a slice=== |
||
<syntaxhighlight lang="zig">/// Asserts that ` |
<syntaxhighlight lang="zig">/// Asserts that `array`.len >= 1. |
||
pub fn reduce(comptime T: type, comptime applyFn: fn (T, T) T, array: []const T) T { |
pub fn reduce(comptime T: type, comptime applyFn: fn (T, T) T, array: []const T) T { |
||
var val: T = array[0]; |
var val: T = array[0]; |