Add peek and reset methods to Iterator(Inner)

This commit is contained in:
Luuk Machielse 2025-12-08 09:02:42 +01:00
parent ae512b5ae7
commit 0e6ad0cde9

View file

@ -1,4 +1,5 @@
const std = @import("std");
const assert = std.debug.assert;
pub fn iter(comptime T: type) type {
return struct {
@ -76,14 +77,31 @@ pub fn Iterator(comptime Inner: type) type {
pub const Item = Inner.Item;
pub const capabilities = .{
.next = @hasDecl(Inner, "next"),
.peek = @hasDecl(Inner, "peek"),
.reset = @hasDecl(Inner, "reset"),
};
const _Inner = Inner;
const Self = @This();
pub fn next(self: *Self) ?Item {
comptime assert(capabilities.next);
return self.inner.next();
}
pub fn peek(self: *Self) ?Item {
comptime assert(capabilities.peek);
return self.inner.peek();
}
pub fn reset(self: *Self) void {
comptime assert(capabilities.reset);
return self.inner.reset();
}
pub fn map(
self: Self,
comptime T: type,