Skip to content

Commit

Permalink
foldl/foldr based enumerations
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Lentz committed Aug 19, 2013
1 parent b214e09 commit 8213f92
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tree-common.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,16 @@
(kvlr (k v l r) node
(fold (the-fn k v (fold base r)) l)))))
(fold base node)))


(defun node/reverse-fold (fn base node)
(labels ((the-fn (k &optional v a)
(funcall (alexandria:ensure-function fn) k v a))
(fold (base node)
(if (empty? node) base
(kvlr (k v l r) node
(fold (the-fn k v (fold base l)) r)))))
(fold base node)))


(defun node/iter (node fn)
"For the side-effect, apply FN to each node of the tree rooted at NODE"
Expand Down
1 change: 1 addition & 0 deletions tree-package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
:node/remove-greatest
:node/concat2
:node/inorder-fold
:node/reverse-fold
:node/iter
:node/at-index
:node/find
Expand Down

0 comments on commit 8213f92

Please sign in to comment.