diff options
Diffstat (limited to 'src/example.zig')
| -rw-r--r-- | src/example.zig | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/example.zig b/src/example.zig index e20eb31..7598008 100644 --- a/src/example.zig +++ b/src/example.zig @@ -36,10 +36,13 @@ pub fn main() !void { const itemsSlice: []i32 = items[0..items.len]; var buffer: [16]i32 = undefined; var buffSlice: []i32 = buffer[0..16]; - func.map(iterThenMul2, itemsSlice, &buffSlice); + func.mapBuff(iterThenMul2, itemsSlice, &buffSlice); const bufferAlloc = try func.mapAlloc(allocator, iterThenMul2, itemsSlice); defer allocator.free(bufferAlloc); - const filtered = func.filter(isEven, itemsSlice); + const filtered = try func.filterAlloc(allocator, isEven, itemsSlice); + defer allocator.free(filtered); + const scanned = try func.scanlAlloc(allocator, add, 0, itemsSlice); + defer allocator.free(scanned); std.debug.print("curry(add)(4)(5) = {any}\n", .{ curriedAddResult }); std.debug.print("compose(mul2, iter)(5) = {d}\n", .{ composed }); @@ -56,12 +59,18 @@ pub fn main() !void { } std.debug.print("}}\n", .{}); + std.debug.print("scanl(add, 0, items) = {{ ", .{}); + for(scanned) |item| { + std.debug.print("{d}, ", .{item}); + } + std.debug.print("}}\n", .{}); + std.debug.print("mapAlloc(allocator, compose(mul2, iter), []i32{{ 0, 1, 2, 3, 4 }}) = {{ ", .{}); for(bufferAlloc) |item| { std.debug.print("{d}, ", .{item}); } std.debug.print("}}\n", .{}); - std.debug.print("foldl(add, 0, bufferAlloc) = {d}\n", .{func.foldl(add, 0, bufferAlloc)}); + std.debug.print("foldl(add, 0, items) = {d}\n", .{func.foldl(add, 0, itemsSlice)}); std.debug.print("I(5) = {any}\n", .{c.I(5)}); std.debug.print("K(5)(7) = {any}\n", .{c.K(5)(7)}); std.debug.print("(S K S K)(5)(7) = {any}\n", .{((c.S(c.K)(c.S)(c.K))(mul2)(func.curry(add)(3)))(7)}); |
