ryoakg
10/28/2017 - 7:23 AM

commons-lang-numeric-range.clj

(set-env! :dependencies '[;; https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
                          [org.apache.commons/commons-lang3 "3.6"]])

(let [r (org.apache.commons.lang3.Range/between 1 4)]
  (->> (range 6)
       (map (juxt identity #(.contains r %)))))
;; => ([0 false] [1 true] [2 true] [3 true] [4 true] [5 false])

(let [r (org.apache.commons.lang3.Range/between 1.1 4.8)]
  (->> [0.5 2.4 10.8]
       (map (juxt identity #(.contains r %)))))
;; => ([0.5 false] [2.4 true] [10.8 false])

(let [r (org.apache.commons.lang3.Range/between 1 4)]
  [(.getMinimum r) (.getMaximum r)])
;; => [1 4]

(let [r (org.apache.commons.lang3.Range/between 1 4)]
  (.contains r 1.5))
;;; java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Double