authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-10-30 04:33:48 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-10-30 04:33:48 -07:00
log27da3db4b150bbd563d800e369b394c5650dd4f2
tree8f768fafed1a765a3f4e4b86f29d6a41db4e5db4
parent4f8933255778838a5f9a34cade2942e9aeae8415

add matchesNone


2 files changed, 31 insertions(+), 0 deletions(-)

src/lib.zig+1
...@@ -98,3 +98,4 @@ pub usingnamespace @import("./FlippedInt.zig");...@@ -98,3 +98,4 @@ pub usingnamespace @import("./FlippedInt.zig");
98pub usingnamespace @import("./isZigString.zig");98pub usingnamespace @import("./isZigString.zig");
99pub usingnamespace @import("./isIndexable.zig");99pub usingnamespace @import("./isIndexable.zig");
100pub usingnamespace @import("./isSlice.zig");100pub usingnamespace @import("./isSlice.zig");
101pub usingnamespace @import("./matchesNone.zig");
src/matchesNone.zig created+30
...@@ -0,0 +1,30 @@
1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub fn matchesNone(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
14test {
15 const S = struct {
16 fn needle(item: u8) bool {
17 return item > 8;
18 }
19 };
20 try std.testing.expect(matchesNone(u8, &.{ 0, 1, 2, 3, 4, 5 }, S.needle));
21}
22
23test {
24 const S = struct {
25 fn needle(item: u8) bool {
26 return item == 4;
27 }
28 };
29 try std.testing.expect(!matchesNone(u8, &.{ 0, 1, 2, 3, 4, 5 }, S.needle));
30}