Fix #44 (destructuring-pair? mistake)
This commit is contained in:
parent
62375212a8
commit
150a5712de
2 changed files with 19 additions and 4 deletions
|
|
@ -28,8 +28,10 @@
|
||||||
(unreduced-> (-> x# ~expr) ~@exprs)))))
|
(unreduced-> (-> x# ~expr) ~@exprs)))))
|
||||||
|
|
||||||
(defn- pair? [x] (and (vector? x) (= 2 (core/count x))))
|
(defn- pair? [x] (and (vector? x) (= 2 (core/count x))))
|
||||||
(defn- destructuring-pair? [x]
|
(let [kw-or-& #(or (keyword? %) (= '& %))]
|
||||||
(and (pair? x) (not (or (keyword? x) (= '& x)))))
|
(defn- destructuring-pair? [x]
|
||||||
|
(and (pair? x)
|
||||||
|
(not (kw-or-& (first x))))))
|
||||||
|
|
||||||
(defmacro for
|
(defmacro for
|
||||||
"Like clojure.core/for with the first expression being replaced by % (or _). Returns a transducer.
|
"Like clojure.core/for with the first expression being replaced by % (or _). Returns a transducer.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
(ns net.cgrand.xforms-test
|
(ns net.cgrand.xforms-test
|
||||||
(:require [clojure.test :refer [is deftest testing]]
|
(:require [clojure.test :refer [are is deftest testing]]
|
||||||
[net.cgrand.xforms :as x]))
|
[net.cgrand.xforms :as x]))
|
||||||
|
|
||||||
(defn trial
|
(defn trial
|
||||||
|
|
@ -139,4 +139,17 @@
|
||||||
(is (= (range 100) (x/into [] (x/sort) (shuffle (range 100)))))
|
(is (= (range 100) (x/into [] (x/sort) (shuffle (range 100)))))
|
||||||
(is (= (reverse (range 100)) (x/into [] (x/sort >) (shuffle (range 100)))))
|
(is (= (reverse (range 100)) (x/into [] (x/sort >) (shuffle (range 100)))))
|
||||||
(is (= (sort-by str (range 100)) (x/into [] (x/sort-by str) (shuffle (range 100)))))
|
(is (= (sort-by str (range 100)) (x/into [] (x/sort-by str) (shuffle (range 100)))))
|
||||||
(is (= (sort-by str (comp - compare) (range 100)) (x/into [] (x/sort-by str (comp - compare)) (shuffle (range 100))))))
|
(is (= (sort-by str (comp - compare) (range 100)) (x/into [] (x/sort-by str (comp - compare)) (shuffle (range 100))))))
|
||||||
|
|
||||||
|
(deftest destructuring-pair?
|
||||||
|
(let [destructuring-pair? #'x/destructuring-pair?]
|
||||||
|
(are [candidate expected]
|
||||||
|
(= expected (destructuring-pair? candidate))
|
||||||
|
'[a b] true
|
||||||
|
'[a b c] false
|
||||||
|
'[& foo] false
|
||||||
|
'[:as foo] false
|
||||||
|
1 false
|
||||||
|
'(a b) false
|
||||||
|
'{foo bar} false
|
||||||
|
'{foo :bar} false)))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue