Skip to content

Instantly share code, notes, and snippets.

@ideal-knee
Last active August 29, 2015 13:56
Show Gist options
  • Save ideal-knee/9264983 to your computer and use it in GitHub Desktop.
Save ideal-knee/9264983 to your computer and use it in GitHub Desktop.
(def append-fn #(conj (or % []) %2))
(deftest append-fn-test
(testing "works as advertised"
(is (= {:a {:b 1 :c [2]}} (update-in {:a {:b 1}} [:a :c] append-fn 2)))
(is (= {:a {:b 1 :c [2 3]}} (update-in {:a {:b 1 :c [2]}} [:a :c] append-fn 3))) ) )
(def prepend-fn #(into [%2] (or % [])))
(deftest prepend-fn-test
(testing "works as advertised"
(is (= {:a {:b 1 :c [2]}} (update-in {:a {:b 1}} [:a :c] prepend-fn 2)))
(is (= {:a {:b 1 :c [2 3]}} (update-in {:a {:b 1 :c [3]}} [:a :c] prepend-fn 2))) ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment