diff options
| author | Nic Gaffney <gaffney_nic@protonmail.com> | 2025-10-20 01:59:56 -0500 |
|---|---|---|
| committer | Nic Gaffney <gaffney_nic@protonmail.com> | 2025-10-20 02:02:15 -0500 |
| commit | 78d191cbf396d2ea32d920282934aa44f8ade4be (patch) | |
| tree | 825d57cf191a761fa4ef40d543b525d87d9f6141 /src/main.zig | |
| parent | 7093b84120dc899a08508b7da2472c5e3edcc008 (diff) | |
| download | funcz-78d191cbf396d2ea32d920282934aa44f8ade4be.tar.gz | |
inital commit
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..949c368 --- /dev/null +++ b/src/main.zig @@ -0,0 +1,33 @@ +const std = @import("std"); +const func = @import("funcz"); + +fn iter(n: i32) i32 { + return n + 1; +} + +fn mul2(n: i32) i32 { + return n * 2; +} + +pub fn main() !void { + var gpa = std.heap.DebugAllocator(.{}){}; + const allocator = gpa.allocator(); + const iterThenMul2 = func.compose(mul2, iter); + var items = [_]i32{ 0, 1, 2, 3, 4 }; + const itemsSlice: []i32 = items[0..items.len]; + const newItems = try func.mapAlloc(allocator, iterThenMul2, itemsSlice); + defer allocator.free(newItems); + var buffer: [128]i32 = undefined; + func.map(iterThenMul2, itemsSlice, &buffer); + std.debug.print("compose(mul2, iter)(5) = {d}\n", .{ iterThenMul2(5) }); + std.debug.print("mapAlloc(allocator, compose(mul2, iter), []i32{{ 0, 1, 2, 3, 4 }}) = {{ ", .{}); + for(newItems) |item| { + std.debug.print("{d}, ", .{item}); + } + std.debug.print("}}\n", .{}); + std.debug.print("map(compose(mul2, iter), []i32{{ 0, 1, 2, 3, 4 }}, &buffer) = {{ ", .{}); + for(buffer[0..items.len]) |item| { + std.debug.print("{d}, ", .{item}); + } + std.debug.print("}}\n", .{}); +} |
