Knows his way around a tree.
Library of functions for dealing with tree data structures. map
, filter
, reduce
and more.
Add the following to :dependencies
in your project.clj
:
[squirrel "0.1.0"]
Make a tree node:
squirrel.core=> (squirrel.node/make 1)
{:data 1}
Use the shorthand:
squirrel.core=> (require '[squirrel.node :refer [node]])
nil
squirrel.core=> (node 1)
{:data 1}
With aggregated data:
squirrel.core=> (node {:x 10 :y "zzz"})
{:data {:x 10, :y "zzz"}}
Trees are nodes with children nodes attached to them:
squirrel.core=> (node 1 [(node 2) (node 3)])
{:data 1, :children [{:data 2} {:data 3}]}
Map:
squirrel.core=> (require '[squirrel.tree :as tree])
nil
squirrel.core=> (tree/map #(update % :data * 10)
#_=> (node 1 [(node 2) (node 3)]))
{:data 10, :children [{:data 20} {:data 30}]}
Filter:
squirrel.core=> (tree/filter (comp odd? :data)
#_=> (node 1 [(node 2) (node 3) (node 4)]))
{:data 1, :children [{:data 3}]}
Reduce:
squirrel.core=> (tree/reduce +
#_=> (node 1 [(node 2) (node 3)])
#_=> :depth-first)
6
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close