Added README

This commit is contained in:
Luuk Machielse 2025-12-06 23:24:59 +01:00
parent 2c091d9d22
commit fed67e2571

62
README.md Normal file
View file

@ -0,0 +1,62 @@
# Iterating
A simple iterating library for the Zig programming language
## Getting started
To add iterating to your `build.zig.zon`, run
```bash
zig fetch --save=iterating https://codeberg.org/kaasboteram/zig-iterating/archive/main.tar.gz
```
and add
```zig
const iterating = b.dependency("iterating", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("iterating", iterating.module("iterating"));
```
to your `build.zig` in order to make it available in your executable
## Examples
```zig
test "basic usage" {
const allocator = std.testing.allocator;
const arith = struct {
fn is_square(x: i32) bool {
const sqrt = @sqrt(@as(f32, @floatFromInt(x)));
return sqrt == @floor(sqrt);
}
};
const items = try iter(i32)
.once(-100)
.chain(
iter(i32)
.rangeInclusive(1, 100)
.filter(arith.is_square)
.chain(iter(i32)
.range(0, 10)),
)
.toOwnedSlice(allocator);
defer allocator.free(items);
try std.testing.expectEqualSlices(
i32,
&[_]i32{ -100, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
items,
);
}
```
## Thanks
This project took a lot of inspiration from [enumerable](https://github.com/lawrence-laz/zig-enumerable), which is currently unmaintained. The main differences are that iterating works in Zig 0.15.x and includes a wider range of "utility iterators" (e.g: `Empty`, `Once`) by default compared to enumerable.