aboutsummaryrefslogtreecommitdiff
path: root/src/slice.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/slice.zig')
-rw-r--r--src/slice.zig47
1 files changed, 0 insertions, 47 deletions
diff --git a/src/slice.zig b/src/slice.zig
deleted file mode 100644
index 1e4a095..0000000
--- a/src/slice.zig
+++ /dev/null
@@ -1,47 +0,0 @@
-// SPDX-FileCopyrightText: 2024 Himbeer <himbeer@disroot.org>
-//
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-pub fn Filter(comptime T: type, comptime U: type) type {
- return struct {
- pub const Predicate = *const fn (T, U) bool;
-
- buffer: []const T,
- index: ?usize,
- predicate: Predicate,
- matcher: U,
-
- const Self = @This();
-
- pub fn new(buffer: []const T, predicate: Predicate, matcher: U) Self {
- return .{
- .buffer = buffer,
- .index = 0,
- .predicate = predicate,
- .matcher = matcher,
- };
- }
-
- pub fn next(self: *Self) ?T {
- const start = self.index orelse return null;
-
- const index = for (self.buffer[start..], 0..) |elem, skipped| {
- if (self.predicate(elem, self.matcher)) {
- break start + skipped;
- }
- } else null;
-
- if (index) |i| {
- self.index = if (1 + i < self.buffer.len) 1 + i else null;
- return self.buffer[i];
- }
-
- self.index = null;
- return null;
- }
-
- pub fn reset(self: *Self) void {
- self.index = 0;
- }
- };
-}