summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib.c10
-rw-r--r--tests/010/tree.tl5
-rw-r--r--txr.121
3 files changed, 36 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 45ec1417..3f2a9616 100644
--- a/lib.c
+++ b/lib.c
@@ -857,6 +857,16 @@ void seq_iter_init_with_info(val self, seq_iter_t *it,
}
}
}
+ if (it->inf.obj->co.cls == tree_iter_s)
+ {
+ it->ui.iter = if3(support_rewind,
+ copy_tree_iter(it->inf.obj),
+ it->inf.obj);
+ it->ul.len = 0;
+ it->get = seq_iter_get_tree;
+ it->peek = seq_iter_peek_tree;
+ break;
+ }
/* fallthrough */
default:
switch (it->inf.kind) {
diff --git a/tests/010/tree.tl b/tests/010/tree.tl
index b41e7973..06d02ce6 100644
--- a/tests/010/tree.tl
+++ b/tests/010/tree.tl
@@ -166,6 +166,11 @@
(copy-search-tree tr) #T((identity < =) 1 2 3)
(make-similar-tree tr) #T((identity < =))))
+(test
+ (collect-each ((el (tree-begin #T(() 1 2 3 4 5) 2 5)))
+ (* 10 el))
+ (20 30 40))
+
(mtest
(uni #T(() "a" "b") #T(() "b" "c")) ("a" "b" "c")
(diff #T(() "a" "b") #T(() "b" "c")) ("a")
diff --git a/txr.1 b/txr.1
index af3fb16a..9f8dc04f 100644
--- a/txr.1
+++ b/txr.1
@@ -34636,6 +34636,14 @@ and
are equivalent to
.codn "(iter-begin X)" .
+Search trees are iterable. Iteration entails an in-order visits of the elements
+of a tree. A tree iterator created by
+.code tree-begin
+is also iterable. It is unspecified whether iteration over a
+.code tree-iter
+object modifies that object to perform the traversal, or whether it uses a copy
+of the iterator.
+
If
.code seq
is not an iterable object, an error exception is thrown.
@@ -51866,6 +51874,19 @@ function to the returned
.code tree-iter
object.
+A
+.code tree-iter
+object is iterable.
+
+.TP* Example:
+
+.verb
+ (collect-each ((el (tree-begin #T(() 1 2 3 4 5)
+ 2 5)))
+ (* 10 el))
+ --> (20 30 40)
+.brev
+
.coNP Function @ tree-reset
.synb
.mets (tree-reset < iter < tree >> [ low-key <> [ high-key ]])