diff options
Diffstat (limited to 'src/compose.zig')
| -rw-r--r-- | src/compose.zig | 19 |
1 files changed, 18 insertions, 1 deletions
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)}); +} |
