1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub fn matchesAll(comptime T: type, haystack: []const T, comptime needle: fn (T) bool) bool {
6 for (haystack) |c| {
7 if (!needle(c)) {
8 return false;
9 }
10 }
11 return true;
12}
13
14const S = struct {
15 fn needle(item: u8) bool {
16 return item == 4;
17 }
18};
19test {
20 try std.testing.expect(matchesAll(u8, &.{ 4, 4, 4, 4, 4, 4 }, S.needle));
21}
22test {
23 try std.testing.expect(!matchesAll(u8, &.{ 4, 4, 4, 3, 4, 4 }, S.needle));
24}
25test {
26 try std.testing.expect(!matchesAll(u8, &.{ 0, 1, 2, 3, 4, 5 }, S.needle));
27}
28test {
29 try std.testing.expect(!matchesAll(u8, &.{ 5, 6, 7, 8, 9, 0 }, S.needle));
30}