feat: iterator.While, slimmed comments in saccharine
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user