Prepends an element to the tree.
Prepends an element to the tree.
the element to prepend
the measure used to update the tree's measure
the new tree with the element prepended
Appends an element to the tree.
Appends an element to the tree.
the element to append
the measure used to update the tree's structure
the new tree with the element appended
Traverses the tree until a predicate on an element becomes true
, and then returns that
element.
Traverses the tree until a predicate on an element becomes true
, and then returns that
element. Note that if pred
returns false
for every element, the last element in the
tree is returned (rather than a runtime exception being thrown).
If the tree is empty, this throws a runtime exception.
a test function applied to the elements of the tree from left to right, until a
the test returns true
.
the discerning element
Returns the first (left-most) element in the tree.
Returns the first (left-most) element in the tree. Throws a runtime exception if performed on an empty tree.
the head element
Returns the first (left-most) element in the tree as an option.
Returns the first (left-most) element in the tree as an option.
the head element (Some
), or None
if the tree is empty
Drops the last element of the tree.
Drops the last element of the tree.
the tree where the last element has been removed
Queries whether the tree is empty or not
Queries whether the tree is empty or not
true
if the tree is empty
Creates an Iterator
over the elements of the tree
Creates an Iterator
over the elements of the tree
a fresh Iterator
for the tree elements
Returns the last (right-most) element in the tree.
Returns the last (right-most) element in the tree. Throws a runtime exception if performed on an empty tree.
the last element
Returns the last (right-most) element in the tree as an option.
Returns the last (right-most) element in the tree as an option.
the last element (Some
), or None
if the tree is empty
Queries the measure of the tree, which might be its size or sum
Queries the measure of the tree, which might be its size or sum
the measure of the tree
Same as span1
, but prepends the discerning element to the right tree, returning the left and right tree.
Same as span1
, but prepends the discerning element to the right tree, returning the left and right tree.
Unlike span1
, this is an allowed operation on an empty tree.
a test function applied to the elements of the tree from left to right, until a
the test returns false
.
the split tree, as a Tuple2
with the left and the right tree
Traverses the tree until a predicate on an element becomes false
, and then splits the tree,
returning the elements before that element (the prefix for which the predicate holds),
the element itself (the first for which the predicate does not hold), and the remaining elements.
Traverses the tree until a predicate on an element becomes false
, and then splits the tree,
returning the elements before that element (the prefix for which the predicate holds),
the element itself (the first for which the predicate does not hold), and the remaining elements.
This method is somewhat analogous to the span
method in standard Scala collections, the difference
being that the predicate tests the tree's measure and not individual elements.
Note that the returned discerning element corresponds to the last element in the tree, if
pred
returns true
for every element (rather than a runtime exception being thrown).
If the tree is empty, this throws a runtime exception.
a test function applied to the elements of the tree from left to right, until a
the test returns true
.
the split tree, as a Tuple3
with the left tree, the discerning element, and the right tree
Returns a copy of the tree with the first (head) element removed.
Returns a copy of the tree with the first (head) element removed. Throws a runtime exception if performed on an empty tree.
the measure used to update the tree's structure
the new tree with the first element removed
Converts the tree to a List
representation.
Converts the tree to a List
representation.
a List
constructed from the elements in the tree