diff options
| author | Nic Gaffney <gaffney_nic@protonmail.com> | 2026-02-18 16:47:14 -0600 |
|---|---|---|
| committer | Nic Gaffney <gaffney_nic@protonmail.com> | 2026-02-18 16:47:14 -0600 |
| commit | d872eceeb6f082abeb3a41d8e1f6e9db53ec7a6e (patch) | |
| tree | 7025db320ffa1f5e42055ec73d02b2fb6a6e7af8 | |
| parent | 813b6631de7aa296c23e2471589d66625aa6ce15 (diff) | |
| download | funcz-d872eceeb6f082abeb3a41d8e1f6e9db53ec7a6e.tar.gz | |
Added fnInput and fnOutput
| -rw-r--r-- | build.zig | 2 | ||||
| -rw-r--r-- | src/compose.zig | 19 | ||||
| -rw-r--r-- | src/util.zig | 8 |
3 files changed, 27 insertions, 2 deletions
@@ -2,7 +2,7 @@ const std = @import("std"); pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); + const optimize = b.standardOptimizeOption(.{.preferred_optimize_mode = .ReleaseFast}); const rootmod =b.addModule("funcz", .{ .root_source_file = b.path("src/root.zig"), diff --git a/src/compose.zig b/src/compose.zig index 442b21b..f17dcf2 100644 --- a/src/compose.zig +++ b/src/compose.zig @@ -7,7 +7,7 @@ const typeVerify = @import("util.zig").typeVerify; /// Function composition /// Type signature: (a -> b) -> (b -> c) -> (a -> c) /// `outerFunc` and `innerFunc` are functions of types `b -> c` and `a -> b` respectively -pub fn compose( +pub inline fn compose( comptime outerFunc: anytype, comptime innerFunc: anytype ) blk:{ @@ -25,3 +25,20 @@ pub fn compose( } }.func; } + +fn testAbs(n: i32) u32 { + return if (n > 0) @intCast(n) else @intCast(0 - n); +} + +fn testNumToString(n: u32) []const u8 { + var buff: [16]u8 = undefined; + buff[0] = std.fmt.digitToChar(@intCast(n), .lower); + return buff[0..1]; +} + +test { + const t = std.testing; + _=t; + const absToString = compose(testNumToString, testAbs); + std.debug.print("{s}\n", .{absToString(-5)}); +} diff --git a/src/util.zig b/src/util.zig index 8de989e..6046264 100644 --- a/src/util.zig +++ b/src/util.zig @@ -14,3 +14,11 @@ pub fn typeVerify(T: type, expected: anytype) Type { @compileError("Expected one of " ++ @tagName(e) ++ ", found " ++ @typeName(T)); return realTypeInfo; } + +pub inline fn fnInput(f: anytype) type { + return typeVerify(@TypeOf(f), .{ .@"fn" }).@"fn".params[0].type.?; +} + +pub inline fn fnOutput(f: anytype) type { + return typeVerify(@TypeOf(f), .{ .@"fn" }).@"fn".return_type.?; +} |
