Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shunkeen/zignite
A lazy stream (iterator) library for Zig
https://github.com/shunkeen/zignite
Last synced: 3 months ago
JSON representation
A lazy stream (iterator) library for Zig
- Host: GitHub
- URL: https://github.com/shunkeen/zignite
- Owner: shunkeen
- License: mit
- Created: 2022-08-11T09:11:35.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-24T02:21:39.000Z (about 2 years ago)
- Last Synced: 2024-08-03T04:08:45.328Z (7 months ago)
- Language: Zig
- Homepage:
- Size: 129 KB
- Stars: 24
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.example.zig
- License: LICENSE
Awesome Lists containing this project
- awesome-zig - zignite๐๏ธA lazy stream (iterator) library for Zig
README
const zignite = @import("src/zignite.zig");
const std = @import("std");fn even(x: usize) bool {
return @mod(x, 2) == 0;
}const RepeatTake = zignite.Repeat(usize).Take();
fn repeatTake(x: usize) RepeatTake {
return zignite.repeat(usize, x).take(x);
}test "Example Code 1" {
const x = zignite
.range(usize, 0, 100) // { 0, 1, ..., 99 }
.filter(even) // { 0, 2, ..., 98 }
.flatMap(RepeatTake, repeatTake) // { 2, 2, 4, 4, 4, 4, ..., 98 }
.sum();try std.testing.expect(x == 161700);
}test "Example Code 2" {
const lazy = zignite
.range(usize, 1, 10) // { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
.filter(even); // { 2, 4, 6, 8, 10 }try std.testing.expect(lazy.sum() == 30);
try std.testing.expect(lazy.product() == 3840);
}test "Example Code 3" {
const allocator = std.testing.allocator;
const slice = "Example Code 3";// []const u8 -> BoundedArray(u8, 50)
const bounded_array = try zignite.fromSlice(u8, slice).toBoundedArray(50);// BoundedArray(u8, 50) -> ArrayList(u8)
var array_list = try zignite.fromBoundedArray(u8, 50, &bounded_array).toArrayList(allocator);
defer array_list.deinit();// ArrayList(u8) -> []const u8
var buffer: [50]u8 = undefined;
const slice2 = zignite.fromArrayList(u8, &array_list).toSlice(&buffer).?;try std.testing.expect(std.mem.eql(u8, slice, slice2));
}