diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/example.zig (renamed from src/main.zig) | 12 | ||||
| -rw-r--r-- | src/root.zig (renamed from src/lib.zig) | 1 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/main.zig b/src/example.zig index bffa1ae..cc3d2c8 100644 --- a/src/main.zig +++ b/src/example.zig @@ -21,14 +21,20 @@ fn addThenMultiply(n: i32, m: i32, q: i32) i32 { pub fn main() !void { var gpa = std.heap.DebugAllocator(.{}){}; const allocator = gpa.allocator(); + // Currying + const curriedAddResult = func.curry(add)(4)(5); + // Composition const iterThenMul2 = func.compose(mul2, iter); + const composed = iterThenMul2(5); + // Map var items = [_]i32{ 0, 1, 2, 3, 4 }; const itemsSlice: []i32 = items[0..items.len]; - std.debug.print("curry(add)(4)(5) = {any}\n", .{ func.curry(add)(4)(5) }); - std.debug.print("compose(mul2, iter)(5) = {d}\n", .{ iterThenMul2(5) }); + const buffer = try func.mapAlloc(allocator, iterThenMul2, itemsSlice); + + std.debug.print("curry(add)(4)(5) = {any}\n", .{ curriedAddResult }); + std.debug.print("compose(mul2, iter)(5) = {d}\n", .{ composed }); std.debug.print("mapAlloc(allocator, compose(mul2, iter), []i32{{ 0, 1, 2, 3, 4 }}) = {{ ", .{}); // func.map(func: anytype, items: anytype, buffer: anytype) - const buffer = try func.mapAlloc(allocator, func.curry(addThenMultiply)(1)(2), itemsSlice); for(buffer) |item| { std.debug.print("{d}, ", .{item}); } diff --git a/src/lib.zig b/src/root.zig index 721b2a0..1339904 100644 --- a/src/lib.zig +++ b/src/root.zig @@ -3,3 +3,4 @@ pub const mapAlloc = @import("map.zig").mapAlloc; pub const curry = @import("curry.zig").curry; pub const compose = @import("compose.zig").compose; pub const combinators = @import("combinators.zig"); +pub const Functor = @import("functor.zig").Functor; |
