zoop.tuple
There are three types of Tuple:
empty:.{}raw:.{a, b, ...}tuple:struct { pub const value = .{a, b, ...}; }
The last one is the normalized form, and all calculations on Tuple output are tuple.
tuple.Init
pub fn Init(comptime any: anytype) type;Function: Convert any comptime value into a tuple
parameter:
any: anycomptimevalue
Returns: normalized tuple
example:
const result = tuple.Init(.{.one, .two});result: struct { pub const value = .{.one, .two}; }
const result = tuple.Init(.one);result: struct { pub const value = .{.one}; }
const result = tuple.Init(struct { const x = 1; });result: struct { pub const value = .{struct { const x = 1; }}; }
tuple.Append
pub fn Append(comptime any: anytype, comptime any2: anytype) type;Function: Returns a new tuple, the content of which is the value of any2 added after any
parameter:
any: anycomptimevalueany2: anycomptimevalue
Returns: A new tuple containing any with the contents of any2 appended
example:
const result = tuple.Append(.{.one, .two}, .{.one, .three});result: struct { pub const value = .{.one, .two, .one, .three}; }
tuple.AppendUnique
pub fn AppendUnique(comptime any: anytype, comptime any2: anytype) type;Function: Returns a new tuple, which contains the value of any2 added after any and without duplicates
parameter:
any: anycomptimevalueany2: anycomptimevalue
Returns: A tuple containing any appended with any2 and without duplicates
example:
const result = tuple.AppendUnique(.one, .{.one, .two});result: struct { pub const value = .{.one, .two}; }
tuple.Remove
pub fn Remove(comptime any: anytype, comptime any_remove: anytype) type;Function: Returns a new tuple containing all the values in any that have not appeared in any_remove
parameter:
any: anycomptimevalueany_remove: anycomptimevalue
Returns: A tuple containing all the values in any that are not present in any_remove
example:
const result = tuple.Remove(.{1,2,3,4}, .{2, 3});result: struct { pub const value = .{1, 4}; }
tuple.Unique
pub fn Unique(comptime any: anytype) type;Function: Remove duplicate items in any
parameter:
any: anycomptimevalue
Returns: any tuple after deduplication
example:
const result = tuple.Unique(.{1, 2, 1, 3, 1, 4});result: struct { pub const value = .{1, 2, 3, 4}; }
tuple.Intersection
pub fn Intersection(comptime any: anytype, comptime any2: anytype) typeFunction: Find the intersection of any and any2
any: anycomptimevalueany2: anycomptimevalue
Returns: the intersection of any and any2 tuple
example:
const result = tuple.Intersection(.{ 1, 2, 3, 4 }, .{ 4, 5, 6 });result: struct { pub const value = .{4}; }
tuple.len
pub inline fn len(any: anytype) comptime_int;Function: Calculate the length of any
parameter:
any: anycomptimevalue
Returns: the length of any
example:
const t = std.testing;
try t.expect(tuple.len(.{}) == 0);
try t.expect(tuple.len(8) == 1);
try t.expect(tuple.len(.{1}) == 1);
try t.expect(tuple.len(tuple.Init(.{1, .x})) == 2);tuple.isRaw
pub inline fn isRaw(any: anytype) bool;Function: Test whether any is of raw type
parameter:
any: anycomptimevalue
Return: if it is raw type, return true, otherwise return false
example:
const t = std.testing;
try t.expect(isRaw(.{1,2}) == true);
try t.expect(isRaw(tuple.Init(.{1,2})) == false);tuple.isEmpty
pub inline fn isEmpty(any: anytype) bool;Function: Test whether any is .{}
parameter:
any: anycomptimevalue
Returns: any is .{} returns true otherwise returns false
example:
const t = std.testing;
try t.expect(tuple.isEmpty(.{}) == true);
try t.expect(tuple.isEmpty(.{1}) == false);tuple.existed
pub inline fn existed(any: anytype, val: anytype) bool;Function: Test whether any contains val
parameter:
any: anycomptimevalueval: anycomptimevalue
Returns: any containing val returns true otherwise false
example:
const t = std.testing;
try t.expect(tuple.existed(.{1, 2, .x}, .x) == true);
try t.expect(tuple.existed(.{1, 2, .x}, .y) == false);