Renamed Iter to iter

This commit is contained in:
Luuk Machielse 2025-11-16 14:37:02 +01:00
parent eb0f258138
commit abaade4cdc

View file

@ -1,6 +1,6 @@
const std = @import("std");
pub fn Iter(comptime T: type) type {
pub fn iter(comptime T: type) type {
return struct {
pub fn fromSlice(slice: anytype) Iterator(
if (@typeInfo(@TypeOf(slice)).pointer.is_const) SliceIterConst(T) else SliceIter(T),
@ -15,13 +15,13 @@ pub fn Iter(comptime T: type) type {
test fromSliceOwned {
const testing = @import("std").testing;
var iter = Iter(i32).fromSliceOwned(&.{ 1, 3, 2, 4 });
var it = iter(i32).fromSliceOwned(&.{ 1, 3, 2, 4 });
try testing.expectEqual(1, iter.next());
try testing.expectEqual(3, iter.next());
try testing.expectEqual(2, iter.next());
try testing.expectEqual(4, iter.next());
try testing.expectEqual(null, iter.next());
try testing.expectEqual(1, it.next());
try testing.expectEqual(3, it.next());
try testing.expectEqual(2, it.next());
try testing.expectEqual(4, it.next());
try testing.expectEqual(null, it.next());
}
pub fn range(start: T, end: T) Iterator(Range(T)) {
@ -41,14 +41,14 @@ pub fn Iter(comptime T: type) type {
test empty {
const testing = @import("std").testing;
var it = Iter(i32).empty;
var it = iter(i32).empty;
try testing.expectEqual(null, it.next());
}
};
}
test Iter {
test iter {
const testing = @import("std").testing;
const allocator = testing.allocator;
@ -60,13 +60,13 @@ test Iter {
}
};
const items = try Iter(i32)
const items = try iter(i32)
.once(-100)
.chain(
Iter(i32)
iter(i32)
.rangeInclusive(1, 100)
.filter(arith.is_square)
.chain(Iter(i32)
.chain(iter(i32)
.range(0, 10)),
)
.toOwnedSlice(allocator);
@ -182,8 +182,8 @@ pub fn Iterator(comptime Inner: type) type {
test zip {
const testing = @import("std").testing;
var it = Iter(i32).fromSliceOwned(&.{ 1, 2, 3 })
.zip(Iter(i32).fromSliceOwned(&.{ 4, 5, 6 }));
var it = iter(i32).fromSliceOwned(&.{ 1, 2, 3 })
.zip(iter(i32).fromSliceOwned(&.{ 4, 5, 6 }));
try testing.expectEqualDeep(.{ 1, 4 }, it.next());
try testing.expectEqualDeep(.{ 2, 5 }, it.next());