mirror of
https://codeberg.org/kaasboteram/zig-iterating.git
synced 2025-12-15 09:43:14 +01:00
Add peek and reset methods to Iterator(Inner)
This commit is contained in:
parent
ae512b5ae7
commit
0e6ad0cde9
1 changed files with 18 additions and 0 deletions
18
src/root.zig
18
src/root.zig
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue