authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-03-13 13:53:23 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-03-13 13:53:23 -07:00
logd34ac633f0a0af8d348b66a38e7497d031f027b1
treeba5dd5618c6803da7f789faf25c936948dd15092
parent788c02e94a29be775651d7a61660af7b94d935cc

add lessThanSlice


1 files changed, 12 insertions(+), 0 deletions(-)

src/lib.zig+12
...@@ -220,6 +220,18 @@ pub fn sortBySlice(comptime T: type, items: []T, comptime field: std.meta.FieldE...@@ -220,6 +220,18 @@ pub fn sortBySlice(comptime T: type, items: []T, comptime field: std.meta.FieldE
220 }.f);220 }.f);
221}221}
222222
223pub fn lessThanSlice(comptime T: type) fn (void, T, T) bool {
224 return struct {
225 fn f(_: void, lhs: T, rhs: T) bool {
226 const result = for (0..@min(lhs.len, rhs.len)) |i| {
227 if (lhs[i] < rhs[i]) break true;
228 if (lhs[i] > rhs[i]) break false;
229 } else false;
230 return result;
231 }
232 }.f;
233}
234
223pub fn containsString(haystack: []const string, needle: string) bool {235pub fn containsString(haystack: []const string, needle: string) bool {
224 for (haystack) |item| {236 for (haystack) |item| {
225 if (std.mem.eql(u8, item, needle)) {237 if (std.mem.eql(u8, item, needle)) {