Support Clojure 1.6 by adopting cljx.
Fixes nathanmarz/specter#16. Resolves nathanmarz/specter#18.
This commit is contained in:
parent
ad1c4fdd53
commit
9e215b638e
6 changed files with 90 additions and 84 deletions
22
project.clj
22
project.clj
|
|
@ -1,12 +1,26 @@
|
|||
(def VERSION (.trim (slurp "VERSION")))
|
||||
|
||||
(defproject com.rpl/specter VERSION
|
||||
:dependencies [[org.clojure/clojure "1.7.0"]
|
||||
[org.clojure/clojurescript "0.0-3308"]
|
||||
:dependencies [[org.clojure/clojure "1.6.0"]
|
||||
[org.clojure/clojurescript "0.0-3211"]
|
||||
]
|
||||
:jvm-opts ["-XX:-OmitStackTraceInFastThrow"] ; this prevents JVM from doing optimizations which can remove stack traces from NPE and other exceptions
|
||||
:source-paths ["src"]
|
||||
:test-paths ["test"]
|
||||
:test-paths ["test", "target/test-classes"]
|
||||
:profiles {:dev {:dependencies
|
||||
[[org.clojure/test.check "0.7.0"]]}
|
||||
[[org.clojure/test.check "0.7.0"]]
|
||||
:plugins
|
||||
[[com.keminglabs/cljx "0.6.0"]]
|
||||
:cljx {:builds [{:source-paths ["src"]
|
||||
:output-path "target/classes"
|
||||
:rules :clj}
|
||||
{:source-paths ["src"]
|
||||
:output-path "target/classes"
|
||||
:rules :cljs}
|
||||
{:source-paths ["test"]
|
||||
:output-path "target/test-classes"
|
||||
:rules :clj}
|
||||
{:source-paths ["test"]
|
||||
:output-path "target/test-classes"
|
||||
:rules :cljs}]}}
|
||||
})
|
||||
|
|
|
|||
4
repl.clj
4
repl.clj
|
|
@ -2,11 +2,11 @@
|
|||
(require 'cljs.build.api)
|
||||
(require 'cljs.repl.node)
|
||||
|
||||
(cljs.build.api/build "src"
|
||||
(cljs.build.api/build "target/classes/com/rpl"
|
||||
{:output-to "out/main.js"
|
||||
:verbose true})
|
||||
|
||||
(cljs.repl/repl (cljs.repl.node/repl-env)
|
||||
:watch "src"
|
||||
:watch "target/classes/com/rpl"
|
||||
:output-dir "out"
|
||||
:static-fns true)
|
||||
|
|
|
|||
|
|
@ -1,25 +1,25 @@
|
|||
(ns com.rpl.specter
|
||||
#?(:cljs (:require-macros
|
||||
[com.rpl.specter.macros
|
||||
:refer
|
||||
[pathed-collector
|
||||
variable-pathed-path
|
||||
fixed-pathed-path
|
||||
defparamscollector
|
||||
defparamspath
|
||||
paramscollector
|
||||
paramspath
|
||||
]]
|
||||
))
|
||||
(:use [com.rpl.specter.protocols :only [StructurePath]]
|
||||
#?(:clj [com.rpl.specter.macros :only
|
||||
#+cljs (:require-macros
|
||||
[com.rpl.specter.macros
|
||||
:refer
|
||||
[pathed-collector
|
||||
variable-pathed-path
|
||||
fixed-pathed-path
|
||||
defparamscollector
|
||||
defparamspath
|
||||
paramscollector
|
||||
paramspath]])
|
||||
paramspath
|
||||
]]
|
||||
)
|
||||
(:use [com.rpl.specter.protocols :only [StructurePath]]
|
||||
#+clj [com.rpl.specter.macros :only
|
||||
[pathed-collector
|
||||
variable-pathed-path
|
||||
fixed-pathed-path
|
||||
defparamscollector
|
||||
defparamspath
|
||||
paramscollector
|
||||
paramspath]]
|
||||
)
|
||||
(:require [com.rpl.specter.impl :as i])
|
||||
)
|
||||
|
|
@ -271,7 +271,7 @@
|
|||
(transform* [this structure next-fn]
|
||||
(next-fn (compiled-transform late update-fn structure)))))
|
||||
|
||||
(extend-type #?(:clj clojure.lang.Keyword :cljs cljs.core/Keyword)
|
||||
(extend-type #+clj clojure.lang.Keyword #+cljs cljs.core/Keyword
|
||||
StructurePath
|
||||
(select* [kw structure next-fn]
|
||||
(next-fn (get structure kw)))
|
||||
|
|
@ -279,14 +279,14 @@
|
|||
(assoc structure kw (next-fn (get structure kw)))
|
||||
))
|
||||
|
||||
(extend-type #?(:clj clojure.lang.AFn :cljs function)
|
||||
(extend-type #+clj clojure.lang.AFn #+cljs function
|
||||
StructurePath
|
||||
(select* [afn structure next-fn]
|
||||
(i/filter-select afn structure next-fn))
|
||||
(transform* [afn structure next-fn]
|
||||
(i/filter-transform afn structure next-fn)))
|
||||
|
||||
(extend-type #?(:clj clojure.lang.PersistentHashSet :cljs cljs.core/PersistentHashSet)
|
||||
(extend-type #+clj clojure.lang.PersistentHashSet #+cljs cljs.core/PersistentHashSet
|
||||
StructurePath
|
||||
(select* [aset structure next-fn]
|
||||
(i/filter-select aset structure next-fn))
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
(ns com.rpl.specter.impl
|
||||
#?(:cljs (:require-macros
|
||||
[com.rpl.specter.prot-opt-invoke
|
||||
:refer [mk-optimized-invocation]]
|
||||
[com.rpl.specter.defhelpers :refer [define-ParamsNeededPath]]
|
||||
))
|
||||
#+cljs (:require-macros
|
||||
[com.rpl.specter.prot-opt-invoke
|
||||
:refer [mk-optimized-invocation]]
|
||||
[com.rpl.specter.defhelpers :refer [define-ParamsNeededPath]]
|
||||
)
|
||||
(:use [com.rpl.specter.protocols :only
|
||||
[select* transform* collect-val]])
|
||||
(:require [com.rpl.specter.protocols :as p]
|
||||
[clojure.walk :as walk]
|
||||
[clojure.core.reducers :as r]
|
||||
[clojure.string :as s]
|
||||
#?(:clj [com.rpl.specter.defhelpers :as dh])
|
||||
#+clj [com.rpl.specter.defhelpers :as dh]
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -21,8 +21,7 @@
|
|||
(defprotocol PathComposer
|
||||
(comp-paths* [paths]))
|
||||
|
||||
#?(
|
||||
:clj
|
||||
#+clj
|
||||
(do
|
||||
(defmacro throw* [etype & args]
|
||||
`(throw (new ~etype (pr-str ~@args))))
|
||||
|
|
@ -31,11 +30,10 @@
|
|||
`(throw* IllegalArgumentException ~@args)))
|
||||
|
||||
|
||||
:cljs
|
||||
#+cljs
|
||||
(defn throw-illegal [& args]
|
||||
(throw (js/Error. (apply str args)))
|
||||
)
|
||||
)
|
||||
|
||||
(defn benchmark [iters afn]
|
||||
(time
|
||||
|
|
@ -81,8 +79,7 @@
|
|||
|
||||
(declare bind-params*)
|
||||
|
||||
#?(
|
||||
:clj
|
||||
#+clj
|
||||
(dh/define-ParamsNeededPath
|
||||
clojure.lang.IFn
|
||||
invoke
|
||||
|
|
@ -90,7 +87,7 @@
|
|||
(let [a (object-array args)]
|
||||
(com.rpl.specter.impl/bind-params* this a 0))))
|
||||
|
||||
:cljs
|
||||
#+cljs
|
||||
(define-ParamsNeededPath
|
||||
cljs.core/IFn
|
||||
-invoke
|
||||
|
|
@ -104,7 +101,6 @@
|
|||
rest))]
|
||||
(com.rpl.specter.impl/bind-params* this a 0))
|
||||
))
|
||||
)
|
||||
|
||||
|
||||
(defn bind-params* [^ParamsNeededPath params-needed-path params idx]
|
||||
|
|
@ -126,8 +122,7 @@
|
|||
optimized performance. Instead, you should extend the protocols via an
|
||||
explicit extend-protocol call. \n" obj))
|
||||
|
||||
#?(
|
||||
:clj
|
||||
#+clj
|
||||
|
||||
(defn find-protocol-impl! [prot obj]
|
||||
(let [ret (find-protocol-impl prot obj)]
|
||||
|
|
@ -135,9 +130,8 @@
|
|||
(throw-illegal (no-prot-error-str obj))
|
||||
ret
|
||||
)))
|
||||
)
|
||||
|
||||
#?(:clj
|
||||
#+clj
|
||||
(do
|
||||
(defn structure-path-impl [this]
|
||||
(if (fn? this)
|
||||
|
|
@ -147,10 +141,10 @@
|
|||
|
||||
(defn collector-impl [this]
|
||||
(find-protocol-impl! p/Collector this))
|
||||
))
|
||||
)
|
||||
|
||||
|
||||
#?(:cljs
|
||||
#+cljs
|
||||
(do
|
||||
(defn structure-path-impl [obj]
|
||||
{:select* (mk-optimized-invocation p/StructurePath obj select* 2)
|
||||
|
|
@ -160,7 +154,7 @@
|
|||
(defn collector-impl [obj]
|
||||
{:collect-val (mk-optimized-invocation p/Collector obj collect-val 1)
|
||||
})
|
||||
))
|
||||
)
|
||||
|
||||
(defn coerce-collector [this]
|
||||
(let [cfn (->> this
|
||||
|
|
@ -220,23 +214,21 @@
|
|||
(coerce-path [this]
|
||||
this)
|
||||
|
||||
#?(:clj java.util.List :cljs cljs.core/PersistentVector)
|
||||
#+clj java.util.List #+cljs cljs.core/PersistentVector
|
||||
(coerce-path [this]
|
||||
(comp-paths* this))
|
||||
|
||||
#?@(:cljs [
|
||||
cljs.core/IndexedSeq
|
||||
(coerce-path [this]
|
||||
(coerce-path (vec this)))
|
||||
cljs.core/EmptyList
|
||||
(coerce-path [this]
|
||||
(coerce-path (vec this)))
|
||||
cljs.core/List
|
||||
(coerce-path [this]
|
||||
(coerce-path (vec this)))
|
||||
])
|
||||
#+cljs cljs.core/IndexedSeq
|
||||
#+cljs (coerce-path [this]
|
||||
(coerce-path (vec this)))
|
||||
#+cljs cljs.core/EmptyList
|
||||
#+cljs (coerce-path [this]
|
||||
(coerce-path (vec this)))
|
||||
#+cljs cljs.core/List
|
||||
#+cljs (coerce-path [this]
|
||||
(coerce-path (vec this)))
|
||||
|
||||
#?(:clj Object :cljs default)
|
||||
#+clj Object #+cljs default
|
||||
(coerce-path [this]
|
||||
(cond (structure-path? this) (coerce-structure-path this)
|
||||
(satisfies? p/Collector this) (coerce-collector this)
|
||||
|
|
@ -316,10 +308,10 @@
|
|||
nil
|
||||
(comp-paths* [sp]
|
||||
(coerce-path sp))
|
||||
#?(:clj Object :cljs default)
|
||||
#+clj Object #+cljs default
|
||||
(comp-paths* [sp]
|
||||
(coerce-path sp))
|
||||
#?(:clj java.util.List :cljs cljs.core/PersistentVector)
|
||||
#+clj java.util.List #+cljs cljs.core/PersistentVector
|
||||
(comp-paths* [structure-paths]
|
||||
(if (empty? structure-paths)
|
||||
(coerce-path nil)
|
||||
|
|
@ -357,12 +349,12 @@
|
|||
|
||||
;; cell implementation idea taken from prismatic schema library
|
||||
(defprotocol PMutableCell
|
||||
#?(:clj (get_cell [cell]))
|
||||
#+clj (get_cell [cell])
|
||||
(set_cell [cell x]))
|
||||
|
||||
(deftype MutableCell [^:volatile-mutable q]
|
||||
PMutableCell
|
||||
#?(:clj (get_cell [cell] q))
|
||||
#+clj (get_cell [cell] q)
|
||||
(set_cell [this x] (set! q x)))
|
||||
|
||||
(defn mutable-cell
|
||||
|
|
@ -373,7 +365,7 @@
|
|||
(set_cell cell val))
|
||||
|
||||
(defn get-cell [cell]
|
||||
#?(:clj (get_cell cell) :cljs (.-q cell))
|
||||
#+clj (get_cell cell) #+cljs (.-q cell)
|
||||
)
|
||||
|
||||
(defn update-cell! [cell afn]
|
||||
|
|
@ -395,12 +387,12 @@
|
|||
(append (butlast l) v))
|
||||
|
||||
(extend-protocol SetExtremes
|
||||
#?(:clj clojure.lang.PersistentVector :cljs cljs.core/PersistentVector)
|
||||
#+clj clojure.lang.PersistentVector #+cljs cljs.core/PersistentVector
|
||||
(set-first [v val]
|
||||
(assoc v 0 val))
|
||||
(set-last [v val]
|
||||
(assoc v (-> v count dec) val))
|
||||
#?(:clj Object :cljs default)
|
||||
#+clj Object #+cljs default
|
||||
(set-first [l val]
|
||||
(set-first-list l val))
|
||||
(set-last [l val]
|
||||
|
|
@ -1,22 +1,22 @@
|
|||
(ns com.rpl.specter.core-test
|
||||
#?(:cljs (:require-macros
|
||||
[cljs.test :refer [is deftest]]
|
||||
[cljs.test.check.cljs-test :refer [defspec]]
|
||||
[com.rpl.specter.cljs-test-helpers :refer [for-all+]]
|
||||
[com.rpl.specter.macros :refer [paramsfn]]))
|
||||
#+cljs (:require-macros
|
||||
[cljs.test :refer [is deftest]]
|
||||
[cljs.test.check.cljs-test :refer [defspec]]
|
||||
[com.rpl.specter.cljs-test-helpers :refer [for-all+]]
|
||||
[com.rpl.specter.macros :refer [paramsfn]])
|
||||
(:use
|
||||
#?(:clj [clojure.test :only [deftest is]])
|
||||
#?(:clj [clojure.test.check.clojure-test :only [defspec]])
|
||||
#?(:clj [com.rpl.specter.test-helpers :only [for-all+]])
|
||||
#?(:clj [com.rpl.specter.macros :only [paramsfn]])
|
||||
#+clj [clojure.test :only [deftest is]]
|
||||
#+clj [clojure.test.check.clojure-test :only [defspec]]
|
||||
#+clj [com.rpl.specter.test-helpers :only [for-all+]]
|
||||
#+clj [com.rpl.specter.macros :only [paramsfn]]
|
||||
|
||||
)
|
||||
(:require #?@(:clj [[clojure.test.check.generators :as gen]
|
||||
[clojure.test.check.properties :as prop]]
|
||||
:cljs [[cljs.test.check :as tc]
|
||||
[cljs.test.check.generators :as gen]
|
||||
[cljs.test.check.properties :as prop :include-macros true]]
|
||||
)
|
||||
|
||||
(:require #+clj [clojure.test.check.generators :as gen]
|
||||
#+clj [clojure.test.check.properties :as prop]
|
||||
#+cljs [cljs.test.check :as tc]
|
||||
#+cljs [cljs.test.check.generators :as gen]
|
||||
#+cljs [cljs.test.check.properties :as prop :include-macros true]
|
||||
[com.rpl.specter :as s]))
|
||||
|
||||
;;TODO:
|
||||
|
|
@ -62,7 +62,7 @@
|
|||
))
|
||||
|
||||
(deftest select-one-test
|
||||
(is (thrown? #?(:clj Exception :cljs js/Error) (s/select-one [s/ALL even?] [1 2 3 4])))
|
||||
(is (thrown? #+clj Exception #+cljs js/Error (s/select-one [s/ALL even?] [1 2 3 4])))
|
||||
(is (= 1 (s/select-one [s/ALL odd?] [2 4 1 6])))
|
||||
)
|
||||
|
||||
|
|
@ -393,7 +393,7 @@
|
|||
|
||||
(deftest nil-select-one-test
|
||||
(is (= nil (s/select-one! s/ALL [nil])))
|
||||
(is (thrown? #?(:clj Exception :cljs js/Error) (s/select-one! s/ALL [])))
|
||||
(is (thrown? #+clj Exception #+cljs js/Error (s/select-one! s/ALL [])))
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -538,7 +538,7 @@
|
|||
(s/transform [s/ALL #(comparator % val)] op v)))
|
||||
))
|
||||
|
||||
#?(:clj
|
||||
#+clj
|
||||
(deftest large-params-test
|
||||
(let [path (apply s/comp-paths (repeat 25 s/keypath))
|
||||
m (reduce
|
||||
|
|
@ -550,4 +550,4 @@
|
|||
))
|
||||
;;TODO: there's a bug in clojurescript that won't allow
|
||||
;; non function implementations of IFn to have more than 20 arguments
|
||||
)
|
||||
|
||||
Loading…
Reference in a new issue