aboutsummaryrefslogtreecommitdiff
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
parentc034b4a1291a803028eef8b0950a7090ea54b047 (diff)
downloadfuncz-ca4b29762ac0ed19e1f18474e0df3257f4a74a06.tar.gz
Added README
-rw-r--r--README.md9
-rw-r--r--build.zig4
-rw-r--r--build.zig.zon2
-rw-r--r--src/example.zig (renamed from src/main.zig)12
-rw-r--r--src/root.zig (renamed from src/lib.zig)1
5 files changed, 22 insertions, 6 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7452cec
--- /dev/null
+++ b/README.md
@@ -0,0 +1,9 @@
+# funcz: All the functional tools you need for zig
+
+This is a work in progress library meant for bringing functional ideas to zig
+in easy to understand and reasonable ways.
+
+To add the latest version to your project, simply run
+```
+$ zig fetch --save git+https://git.ngaffney.dev/funcz/#HEAD
+```
diff --git a/build.zig b/build.zig
index 99b3ef9..6de6611 100644
--- a/build.zig
+++ b/build.zig
@@ -7,7 +7,7 @@ pub fn build(b: *std.Build) !void {
const lib = b.addLibrary(.{
.name = "funcz",
.root_module = b.createModule(.{
- .root_source_file = b.path("src/lib.zig"),
+ .root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
}),
@@ -17,7 +17,7 @@ pub fn build(b: *std.Build) !void {
const exe = b.addExecutable(.{
.name = "funczExample",
.root_module = b.createModule(.{
- .root_source_file = b.path("src/main.zig"),
+ .root_source_file = b.path("src/example.zig"),
.imports = &.{ .{.name = "funcz", .module = lib.root_module} },
.target = target,
.optimize = optimize,
diff --git a/build.zig.zon b/build.zig.zon
index ae01ad9..0ab3d38 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -1,6 +1,6 @@
.{
.name = .funcz,
.fingerprint = 0x30f8633228105f1a,
- .version = "0.0.1",
+ .version = "0.1.0",
.paths = .{ "src" },
}
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;