Added Empty(T) and Iter(T).empty

This commit is contained in:
Luuk Machielse 2025-10-10 19:58:08 +02:00
parent 3259d0d888
commit cb94fae03b

View file

@ -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());
}