Imperative set-like data structure.
Primary differences from a simple set:
It is an error to modify a bag (add
, remove
, remove_one
, ...) during iteration
(fold
, iter
, ...).
remove_one t
removes some element from the bag, and returns its value.
remove_one
runs in constant time.
filter_inplace t ~f
removes all the elements from t
that don't satisfy f
.
until_empty t f
repeatedly removes a value v
from t
and runs f v
,
continuing until t
is empty. Running f
may add elements to t
if it
wants.
unchecked_iter t ~f
behaves like iter t ~f
except that f
is allowed to modify
t
. Elements added by f
may or may not be visited, elements removed by f
that
have not been visited will not be visited. It is an (undetected) error to delete the
current element.