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