mirror of
https://codeberg.org/kaasboteram/zig-iterating.git
synced 2025-12-15 09:43:14 +01:00
Added Empty(T) and Iter(T).empty
This commit is contained in:
parent
3259d0d888
commit
cb94fae03b
1 changed files with 22 additions and 0 deletions
22
src/root.zig
22
src/root.zig
|
|
@ -19,6 +19,10 @@ pub fn Iter(comptime T: type) type {
|
|||
pub fn once(value: T) Iterator(Once(T)) {
|
||||
return .{ .inner = .{ .value = value } };
|
||||
}
|
||||
|
||||
pub fn empty() Iterator(Empty(T)) {
|
||||
return .{ .inner = .{} };
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -367,3 +371,21 @@ pub fn SliceIterConst(comptime T: type) type {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub fn Empty(comptime T: type) type {
|
||||
return struct {
|
||||
pub const Item = T;
|
||||
|
||||
pub fn next(_: Empty(T)) ?Item {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
test Empty {
|
||||
const testing = @import("std").testing;
|
||||
|
||||
var it = Iter(i32).empty();
|
||||
|
||||
try testing.expectEqual(null, it.next());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue