Zig utility library
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Document SliceIterator

IamPyu d8f7713c 918a4c38

+11
+11
src/SliceIterator.zig
··· 7 7 slice: []const T, 8 8 index: usize = 0, 9 9 10 + /// Create the SliceIterator from a slice 10 11 pub fn init(slice: []const T) Self { 11 12 return Self{ .slice = slice }; 12 13 } 13 14 15 + /// Return the next value in the iterator but don't increase the index 14 16 pub fn peek(self: *const Self) ?T { 15 17 if (self.index >= self.slice.len) { 16 18 return null; ··· 18 20 return self.slice[self.index]; 19 21 } 20 22 23 + /// Returns the next value in the iterator 21 24 pub fn next(self: *Self) ?T { 22 25 const v = self.peek(); 23 26 self.index += 1; ··· 51 54 } 52 55 std.debug.print("\n", .{}); 53 56 } 57 + 58 + test "peek" { 59 + const array = [_]f32{ 1, 2, 3 }; 60 + var iter = SliceIterator(f32).init(&array); 61 + 62 + const item = iter.peek().?; 63 + try std.testing.expectEqual(1, item); 64 + }