Back

prewalk (clj)

(source)

function

(prewalk f form)
Like postwalk, but does pre-order traversal.

Examples

clojure
(ns clojure.test-clojure.clojure-walk
  (:require [clojure.walk :as w])
  (:use clojure.test))

(deftest t-prewalk-replace
  (is (= (w/prewalk-replace {:a :b} [:a {:a :a} (list 3 :c :a)])
         [:b {:b :b} (list 3 :c :b)])))

(deftest t-prewalk-order
  (is (= (let [a (atom [])]
           (w/prewalk (fn [form] (swap! a conj form) form)
                      [1 2 {:a 3} (list 4 [5])])
           @a)
         [[1 2 {:a 3} (list 4 [5])]
          1 2 {:a 3} [:a 3] :a 3 (list 4 [5])
          4 [5] 5])))
clojure/clojure
(ns clojure.test-clojure.clojure-walk
  (:require [clojure.walk :as w])
  (:use clojure.test))

(deftest t-prewalk-replace
  (is (= (w/prewalk-replace {:a :b} [:a {:a :a} (list 3 :c :a)])
         [:b {:b :b} (list 3 :c :b)])))

(deftest t-prewalk-order
  (is (= (let [a (atom [])]
           (w/prewalk (fn [form] (swap! a conj form) form)
                      [1 2 {:a 3} (list 4 [5])])
           @a)
         [[1 2 {:a 3} (list 4 [5])]
          1 2 {:a 3} [:a 3] :a 3 (list 4 [5])
          4 [5] 5])))
clojure/clojurescript
(ns cljs.walk-test
  (:require [cljs.test :refer-macros [deftest testing is]]
            [clojure.walk :as w]))

(deftest t-prewalk-replace
  (is (= (w/prewalk-replace {:a :b} [:a {:a :a} (list 3 :c :a)])
        [:b {:b :b} (list 3 :c :b)])))

(deftest t-prewalk-order
  (is (= (let [a (atom [])]
           (w/prewalk (fn [form] (swap! a conj form) form)
             [1 2 {:a 3} (list 4 [5])])
           @a)
        [[1 2 {:a 3} (list 4 [5])]
         1 2 {:a 3} [:a 3] :a 3 (list 4 [5])
         4 [5] 5])))
athensresearch/athens
(ns athens.common-db-test
  (:require
    [athens.common-db :as common-db]
    [athens.common-events.bfs :as bfs]
    [clojure.test :as t]
    [clojure.walk :as walk]
    [datascript.core :as d])
  #?(:clj
     (:import
       (clojure.lang
         ExceptionInfo))))


(t/deftest get-block-property-document
  (let [db (bfs/db-from-repr [{:page/title "title"
                               :block/properties
                               {"key" #:block{:uid    "uid1"
                                              :string "one"
                                              :children
                                              [#:block{:uid    "uid2"
                                                       :string "two"}]
                                              :properties
                                              {"another-key"
                                               #:block{:uid    "uid3"
                                                       :string "three"}}}}}])
        remove-create-edits (fn [x]
                              (walk/prewalk (fn [node]
                                              (if (map? node)
                                                (dissoc node :block/create :block/edits)
                                                node)) x))]
arcadia-unity/Arcadia
(ns clojure.test-clojure.clojure-walk
  (:require [clojure.walk :as w])
  (:use clojure.test))

(deftest t-prewalk-replace
  (is (= (w/prewalk-replace {:a :b} [:a {:a :a} (list 3 :c :a)])
         [:b {:b :b} (list 3 :c :b)])))

(deftest t-prewalk-order
  (is (= (let [a (atom [])]
           (w/prewalk (fn [form] (swap! a conj form) form)
                      [1 2 {:a 3} (list 4 [5])])
           @a)
         [[1 2 {:a 3} (list 4 [5])]
          1 2 {:a 3} [:a 3] :a 3 (list 4 [5])
          4 [5] 5])))
replikativ/datahike
(ns datahike.test.entity-test
  (:require
   [#?(:cljs cljs.reader :clj clojure.edn) :as edn]
   #?(:cljs [cljs.test    :as t :refer-macros [is deftest testing]]
      :clj  [clojure.test :as t :refer        [is deftest testing]])
   [clojure.walk]
   [datahike.api :as d]
   [datahike.db :as db]
   [datahike.impl.entity :as de]
   [datahike.test.core-test :as tdc]))

(deftest test-entity-walk
  (let [ivan {:name "Ivan", :age 19, :aka #{"X" "Y"}}
        db (-> (db/empty-db {:aka {:db/cardinality :db.cardinality/many}})
               (d/db-with [(assoc ivan :db/id 1)]))
        e  (d/entity db 1)]
    (is (= (clojure.walk/walk identity identity e) ivan))
    (is (= (clojure.walk/postwalk identity e) ivan))
    (is (= (clojure.walk/prewalk identity e) ivan))))