feat: iterator.While, slimmed comments in saccharine

This commit is contained in:
2026-02-11 19:13:06 -05:00
parent 87f2370d81
commit e1ec3a3c09
2 changed files with 12 additions and 12 deletions

View File

@@ -81,6 +81,17 @@ func (i Iterator[T]) Done() bool {
return i.index == len(i.items)
}
// While increments the iterator as long as the current item satisfies the
// predicate. The first item that does not match is left unconsumed.
func (i *Iterator[T]) While(fn func(T) bool) {
for !i.Done() {
if !fn(i.MustGet()) {
return
}
i.Forward()
}
}
// Try attempts to perform an operation using the iterator. If the operation
// succeeds, the iterator is updated. If the operation fails, the iterator is
// rolled back, and an error is returned.