aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNic Gaffney <gaffney_nic@protonmail.com>2025-10-23 17:21:19 -0500
committerNic Gaffney <gaffney_nic@protonmail.com>2025-10-23 17:21:19 -0500
commitca4b29762ac0ed19e1f18474e0df3257f4a74a06 (patch)
tree70b5b22790016f8a82c6226f94c31debba165e4f /src
parentc034b4a1291a803028eef8b0950a7090ea54b047 (diff)
downloadfuncz-ca4b29762ac0ed19e1f18474e0df3257f4a74a06.tar.gz
Added README
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;