diff options
| author | Nic Gaffney <gaffney_nic@protonmail.com> | 2025-10-28 20:55:06 -0500 |
|---|---|---|
| committer | Nic Gaffney <gaffney_nic@protonmail.com> | 2025-10-28 20:55:06 -0500 |
| commit | 813b6631de7aa296c23e2471589d66625aa6ce15 (patch) | |
| tree | bfe69e1d47e97dfe95ff22a6e23b5b46680146f7 /src/map.zig | |
| parent | 99c32737fe07bf7dc6094a1326be418ffd00e36f (diff) | |
| download | funcz-813b6631de7aa296c23e2471589d66625aa6ce15.tar.gz | |
Diffstat (limited to 'src/map.zig')
| -rw-r--r-- | src/map.zig | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/map.zig b/src/map.zig index e0d713d..f66fae0 100644 --- a/src/map.zig +++ b/src/map.zig @@ -7,7 +7,7 @@ const typeVerify = @import("util.zig").typeVerify; /// Map a function onto a list of values, using a buffer /// Type signature: `(a -> b) -> [a] -> [b]` /// `func` is of type `a -> b`, where `items` is of type `[a]` and `buffer` is a pointer to a value of type `[b]`. -pub fn map( +pub fn mapBuff( comptime func: anytype, items: []typeVerify(@TypeOf(func), .{ .@"fn" }).@"fn".params[0].type.?, buffer: *[]typeVerify(@TypeOf(func), .{ .@"fn" }).@"fn".return_type.?, @@ -37,7 +37,6 @@ pub fn mapAlloc( } { const funcInfo = typeVerify(@TypeOf(func), .{ .@"fn" }); var result = try allocator.alloc(funcInfo.@"fn".return_type.?, items.len); - for(items, 0..) |item, i| - result[i] = func(item); + mapBuff(func, items, &result); return result; } |
