Last active
August 29, 2015 13:56
-
-
Save ideal-knee/9264983 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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