mirror of
https://codeberg.org/kaasboteram/zig-iterating.git
synced 2025-12-15 09:43:14 +01:00
Added explicit return type to Iterator(T).fold
This commit is contained in:
parent
4c80f07498
commit
c87b7f9d0b
1 changed files with 3 additions and 3 deletions
|
|
@ -100,7 +100,7 @@ pub fn Iterator(comptime Inner: type) type {
|
|||
return .{ .inner = .{ .inner = self.inner } };
|
||||
}
|
||||
|
||||
pub fn fold(self: Self, init: anytype, f: anytype) @typeInfo(@TypeOf(f)).@"fn".return_type.? {
|
||||
pub fn fold(self: Self, comptime T: type, init: T, f: anytype) T {
|
||||
var mutSelf = self;
|
||||
var acc = init;
|
||||
while (mutSelf.next()) |x| {
|
||||
|
|
@ -110,7 +110,7 @@ pub fn Iterator(comptime Inner: type) type {
|
|||
}
|
||||
|
||||
pub fn count(self: Self) usize {
|
||||
return self.fold(@as(usize, 0), struct {
|
||||
return self.fold(usize, 0, struct {
|
||||
fn inc(i: usize, _: Item) usize {
|
||||
return i + 1;
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ pub fn Iterator(comptime Inner: type) type {
|
|||
}
|
||||
|
||||
pub fn last(self: Self) ?Item {
|
||||
return self.fold(@as(?Item, null), struct {
|
||||
return self.fold(?Item, null, struct {
|
||||
inline fn some(_: ?Item, x: Item) ?Item {
|
||||
return x;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue