| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); |
| 4 | |
| 5 | pub fn lessThanSlice(comptime T: type) fn (void, T, T) bool { |
| 6 | return struct { |
| 7 | fn f(_: void, lhs: T, rhs: T) bool { |
| 8 | const result = for (0..@min(lhs.len, rhs.len)) |i| { |
| 9 | if (lhs[i] < rhs[i]) break true; |
| 10 | if (lhs[i] > rhs[i]) break false; |
| 11 | } else false; |
| 12 | return result; |
| 13 | } |
| 14 | }.f; |
| 15 | } |
| 16 | |
| 17 | test { |
| 18 | try std.testing.expect(lessThanSlice(string)({}, "mouse", "possum")); |
| 19 | } |
| 20 | test { |
| 21 | try std.testing.expect(!lessThanSlice(string)({}, "mouse", "kangaroo")); |
| 22 | } |
| 23 | test { |
| 24 | try std.testing.expect(!lessThanSlice(string)({}, "mouse", "mouse")); |
| 25 | } |