authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-03-13 13:53:14 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-03-13 13:53:14 -07:00
log788c02e94a29be775651d7a61660af7b94d935cc
treeb21ca9046ae6ad15ca1ed54ece90d9e55d991fe7
parentf8a50c07032a62651328861353d24485b73d3976

add sortBySlice


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

src/lib.zig+8
...@@ -212,6 +212,14 @@ pub fn sortBy(comptime T: type, items: []T, comptime field: std.meta.FieldEnum(T...@@ -212,6 +212,14 @@ pub fn sortBy(comptime T: type, items: []T, comptime field: std.meta.FieldEnum(T
212 }.f);212 }.f);
213}213}
214214
215pub fn sortBySlice(comptime T: type, items: []T, comptime field: std.meta.FieldEnum(T)) void {
216 std.sort.sort(T, items, {}, struct {
217 fn f(_: void, lhs: T, rhs: T) bool {
218 return lessThanSlice(FieldType(T, field))({}, @field(lhs, @tagName(field)), @field(rhs, @tagName(field)));
219 }
220 }.f);
221}
222
215pub fn containsString(haystack: []const string, needle: string) bool {223pub fn containsString(haystack: []const string, needle: string) bool {
216 for (haystack) |item| {224 for (haystack) |item| {
217 if (std.mem.eql(u8, item, needle)) {225 if (std.mem.eql(u8, item, needle)) {