mirror of
https://codeberg.org/kaasboteram/zig-iterating.git
synced 2025-12-15 09:43:14 +01:00
Added Iterator(T).any and Iterator(T).all
This commit is contained in:
parent
4f57df8f72
commit
3259d0d888
1 changed files with 18 additions and 0 deletions
18
src/root.zig
18
src/root.zig
|
|
@ -111,6 +111,24 @@ pub fn Iterator(comptime Inner: type) type {
|
|||
return acc;
|
||||
}
|
||||
|
||||
pub fn any(self: Self, f: fn (Item) bool) bool {
|
||||
var mutSelf = self;
|
||||
while (mutSelf.next()) |v| {
|
||||
if (f(v)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn all(self: Self, f: fn (Item) bool) bool {
|
||||
var mutSelf = self;
|
||||
while (mutSelf.next()) |v| {
|
||||
if (!f(v)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn count(self: Self) usize {
|
||||
return self.fold(usize, 0, struct {
|
||||
fn inc(i: usize, _: Item) usize {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue