authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-09-01 13:38:25-07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-09-01 13:38:25-07:00
logfeae209ba5cbc9b92a240f2e8e531c1b913bef3f
tree72da6def6790e451f1255d1f0a726dbee6261042
parent285c8f82b4d32760005a1167e0f78c16f8230d06
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add isTuple


3 files changed, 18 insertions(+), 3 deletions(-)

src/isIndexable.zig+1-3
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const extras = @import("./lib.zig");3const extras = @import("./lib.zig");
4const isTuple = extras.isTuple;
45
5pub fn isIndexable(comptime T: type) bool {6pub fn isIndexable(comptime T: type) bool {
6 if (comptime is(.pointer)(T)) {7 if (comptime is(.pointer)(T)) {
...@@ -19,9 +20,6 @@ fn is(comptime id: std.builtin.TypeId) fn (type) bool {...@@ -19,9 +20,6 @@ fn is(comptime id: std.builtin.TypeId) fn (type) bool {
19 };20 };
20 return Closure.trait;21 return Closure.trait;
21}22}
22fn isTuple(comptime T: type) bool {
23 return is(.@"struct")(T) and @typeInfo(T).@"struct".is_tuple;
24}
2523
26test {24test {
27 const array = [_]u8{0} ** 10;25 const array = [_]u8{0} ** 10;
src/isTuple.zig created+15
...@@ -0,0 +1,15 @@
1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub fn isTuple(comptime T: type) bool {
6 return is(.@"struct")(T) and @typeInfo(T).@"struct".is_tuple;
7}
8fn is(comptime id: std.builtin.TypeId) fn (type) bool {
9 const Closure = struct {
10 pub fn trait(comptime T: type) bool {
11 return id == @typeInfo(T);
12 }
13 };
14 return Closure.trait;
15}
src/lib.zig+2
...@@ -89,6 +89,7 @@ pub const compareFnSlice = @import("./compareFnSlice.zig").compareFnSlice;...@@ -89,6 +89,7 @@ pub const compareFnSlice = @import("./compareFnSlice.zig").compareFnSlice;
89pub const sumLen = @import("./sumLen.zig").sumLen;89pub const sumLen = @import("./sumLen.zig").sumLen;
90pub const splitScalarN = @import("./splitScalarN.zig").splitScalarN;90pub const splitScalarN = @import("./splitScalarN.zig").splitScalarN;
91pub const indexOfAggregate = @import("./indexOfAggregate.zig").indexOfAggregate;91pub const indexOfAggregate = @import("./indexOfAggregate.zig").indexOfAggregate;
92pub const isTuple = @import("./isTuple.zig").isTuple;
9293
93test {94test {
94 _ = @import("reduceNumber.zig");95 _ = @import("reduceNumber.zig");
...@@ -167,4 +168,5 @@ test {...@@ -167,4 +168,5 @@ test {
167 _ = @import("sumLen.zig");168 _ = @import("sumLen.zig");
168 _ = @import("splitScalarN.zig");169 _ = @import("splitScalarN.zig");
169 _ = @import("indexOfAggregate.zig");170 _ = @import("indexOfAggregate.zig");
171 _ = @import("isTuple.zig");
170}172}