Improved destructuring

This commit is contained in:
Julien Eluard 2019-04-01 14:52:14 +02:00
parent 480948bf2f
commit d51c14c70a
No known key found for this signature in database
GPG Key ID: 6FD7DB5437FCBEF6
2 changed files with 7 additions and 2 deletions

View File

@ -76,5 +76,7 @@
* :errors, a vector of errors encountered during the destructuring"
[bindings s]
(cond
(sequential? s) (destructure-seq bindings s)
(map? s) (destructure-assoc bindings s)))
(sequential? bindings)
(destructure-seq bindings s)
(map? bindings)
(destructure-assoc bindings s)))

View File

@ -17,6 +17,8 @@
(is (= {:data '{all [1 2 3]}} (destructuring/destructure-seq '[_ _ _ :as all] [1 2 3]))))
(deftest destructure-assoc
(is (= {:data '{a nil b nil}}
(destructuring/destructure-assoc '{a :a b :b} nil)))
(is (= {:data '{a 1 b 2}}
(destructuring/destructure-assoc '{a :a b :b} {:a 1 :b 2})))
#_
@ -35,6 +37,7 @@
(destructuring/destructure-assoc '{a :a b :b c [:c 4] :as all} {:a 1 :b 2 :d 3}))))
(deftest destructure
(is (= {:data '{a nil}} (destructuring/destructure '{a :a} nil)))
(is (= {:data '{a 1}} (destructuring/destructure '[a] [1])))
(is (= {:data '{a 1 b 2}} (destructuring/destructure '[a {b :b}] [1 {:b 2}])))
(is (= {:data '{a 1 b 2 c 3}} (destructuring/destructure '[a [b [c]]] [1 [2 [3]]])))