From 813b6631de7aa296c23e2471589d66625aa6ce15 Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Tue, 28 Oct 2025 20:55:06 -0500 Subject: scanl added, refactored map --- src/map.zig | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/map.zig') 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; } -- cgit v1.2.3