Open gwenzek opened 3 years ago
Take a look at the "FizzBuzz" commit. The pipe to process FizzBuzz added to main.zig looks like this:
const S = pipe.Filters(F.S, []const u8);
try Make.run(@This(), .{
.{ F.gen, .{35} },
.{ .not3, F.exactdiv, .{3} },
.{ .by3not5, F.exactdiv, .{5} },
.{ S.replace, .{ @as([]const u8, "\'FizzBuzz")} }, // Divisible by 3 and 5
.{ .all, F.faninany },
.{ F.console, ._ },
.{ .by3not5 },
.{ S.replace, .{ @as([]const u8, "\'Fizz")} }, // Divisible by 3 but not 5
.{ .all, ._ },
.{ .not3 },
.{ .not3not5, F.exactdiv, .{5} }, // not divisible by 3, check 5
.{ S.replace, .{ @as([]const u8, "\'Buzz")} },
.{ .all, ._ },
.{ .not3not5 }, // route numbers back to faninany
.{ .all, ._ },
});
which outputs
FizzBuzz 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31 32 Fizz 34
Hi, I saw your presentation during the Zig show and got interested. I love the idea of being able to have such high-level programming style in Zig.
But I've some hard time understanding the examples. Could you maybe write a FizzBuzz implementation ?
I've tried myself, but I didn't find a way to properly remove the
console
for the number that divides 3 or 5. Removing any one of them, seems to optimize away all the pipeline. Therefore I'm still printing to the console.My
ack
filter:Output:
Also about the API, I found it a bit awkward that
exactDiv
expect the label for it's output on the left side. I think.{ F.exactdiv, .{3}, .not3 }
would be easier to read.