diff --git a/src/lib.zig b/src/lib.zig index 19999a64f444a22a77bd5757c3ee7f24882c33fb..3caa23f44390d7f84fc827bf445b6f2ea915450d 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -98,3 +98,4 @@ pub usingnamespace @import("./FlippedInt.zig"); pub usingnamespace @import("./isZigString.zig"); pub usingnamespace @import("./isIndexable.zig"); pub usingnamespace @import("./isSlice.zig"); +pub usingnamespace @import("./matchesNone.zig"); diff --git a/src/matchesNone.zig b/src/matchesNone.zig new file mode 100644 index 0000000000000000000000000000000000000000..762a85409716c011b0a38738d987b8502b8d9089 --- /dev/null +++ b/src/matchesNone.zig @@ -0,0 +1,30 @@ +const std = @import("std"); +const string = []const u8; +const extras = @import("./lib.zig"); + +pub fn matchesNone(comptime T: type, haystack: []const T, comptime needle: fn (T) bool) bool { + for (haystack) |c| { + if (needle(c)) { + return false; + } + } + return true; +} + +test { + const S = struct { + fn needle(item: u8) bool { + return item > 8; + } + }; + try std.testing.expect(matchesNone(u8, &.{ 0, 1, 2, 3, 4, 5 }, S.needle)); +} + +test { + const S = struct { + fn needle(item: u8) bool { + return item == 4; + } + }; + try std.testing.expect(!matchesNone(u8, &.{ 0, 1, 2, 3, 4, 5 }, S.needle)); +}