https://github.com/tizee/zig-fp
some iterator patterns for Zig lang
https://github.com/tizee/zig-fp
iterator zig
Last synced: 3 months ago
JSON representation
some iterator patterns for Zig lang
- Host: GitHub
- URL: https://github.com/tizee/zig-fp
- Owner: tizee
- License: apache-2.0
- Created: 2022-07-31T01:37:43.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-07T09:38:18.000Z (almost 4 years ago)
- Last Synced: 2025-03-30T09:51:12.307Z (about 1 year ago)
- Topics: iterator, zig
- Language: Zig
- Homepage:
- Size: 90.8 KB
- Stars: 11
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# zig-fp
Functional programmimng style patterns in Zig lang.
```
zig version
0.10.0-dev.3340+c6f5832bb
```
## Features
- Iterators
- Monad
## Usage
```zig
const std = @import("std");
const it = @import("zig-fp");
fn isEven(val: u32) bool {
return val % 2 == 0;
}
fn toChar(val: u32) u8 {
if(val % 4 == 0) {
return '0';
}else{
return '1';
}
}
fn print(val: u8) void{
std.debug.print("{}\n", .{val});
}
it.range(u32,0,100,1)
.filter(isEven)
.map(toChar)
.for_each(print);
```
> Currently Zig does not support closure but we can achieve similar functionality with `comptime` and `type` to build the context for reusing the same iterator interface.