const std = @import("std"); const typeVerify = @import("util.zig").typeVerify; /// ```zig /// (fn (fn (fn (a) bool, []a) []a) /// ``` /// Filters a slice, only keeping items give `true` when passed into `func` /// Type signature: `(a -> bool) -> [a] -> [a]` /// `func` is of type `a -> bool`, where `items` is of type `[a]` pub fn filter( func: anytype, items: []typeVerify(@TypeOf(func), .{ .@"fn" }).@"fn".params[0].type.?, ) []typeVerify(@TypeOf(func), .{ .@"fn" }).@"fn".params[0].type.? { var output = items; var i: u32 = 0; for (items) |it| if (func(it)) { output[i] = it; i = i + 1; }; return output[0..i]; }