         ([] (xf))
         ([result] (xf result))
         ([result input]
-          (let [next-branch (next-node @branch input)]
+          (let [next-branch (child-at @branch input)]
             (if (is-leaf? next-branch)
               (do
                 (vreset! branch huffman-tree)

(defn is-node? [node] (= (first node) ::node))

(defn leaf-val [node] {:pre (is-leaf? node)} (second node))
(defn lhs-node [node] {:pre (is-node? node)} (nth node 1))
(defn rhs-node [node] {:pre (is-node? node)} (nth node 2))
;; TODO
;; Better use of data abstraction: return children as "(rest node)"
;; It would allow to use the (nth children input) as decoding
;; !!! Make the distinction between the need for get/set and absence of std data structure


;; -----------------------------------------------------------

(def t (make-huffman-tree m))

(defn tests []
  (prn (encode-with t [:a :b :c :d :e]))
  (prn (second (encode [:a :b :c :d :e])))
  (prn (decode t [0 0 0 0 0 1 0 1 1 0 1 1]))
