add functions: contains, index_of, last_index_of
This commit is contained in:
parent
bed886b5ad
commit
326b1eef7a
|
@ -29,6 +29,13 @@
|
||||||
{:fn (fn [s size & [padding-string]]
|
{:fn (fn [s size & [padding-string]]
|
||||||
(StringUtils/center s size (or padding-string " ")))}
|
(StringUtils/center s size (or padding-string " ")))}
|
||||||
|
|
||||||
|
"contains"
|
||||||
|
{:fn (fn [coll value]
|
||||||
|
(if (map? coll)
|
||||||
|
(contains? coll value)
|
||||||
|
; explicit use of '=' to allow testing for falsey values
|
||||||
|
(some #(= value %) coll)))}
|
||||||
|
|
||||||
"dump"
|
"dump"
|
||||||
{:fn (fn [x]
|
{:fn (fn [x]
|
||||||
(with-out-str
|
(with-out-str
|
||||||
|
@ -39,6 +46,20 @@
|
||||||
(with-out-str
|
(with-out-str
|
||||||
(clojure.pprint/print-table x)))}
|
(clojure.pprint/print-table x)))}
|
||||||
|
|
||||||
|
"index_of"
|
||||||
|
{:fn (fn [coll value]
|
||||||
|
(cond
|
||||||
|
(instance? java.util.List coll) (.indexOf coll value)
|
||||||
|
(string? coll) (.indexOf coll value)
|
||||||
|
:else (throw (new Exception (str "'index_if' passed invalid collection type: " (type coll))))))}
|
||||||
|
|
||||||
|
"last_index_of"
|
||||||
|
{:fn (fn [coll value]
|
||||||
|
(cond
|
||||||
|
(instance? java.util.List coll) (.lastIndexOf coll value)
|
||||||
|
(string? coll) (.lastIndexOf coll value)
|
||||||
|
:else (throw (new Exception (str "'last_index_if' passed invalid collection type: " (type coll))))))}
|
||||||
|
|
||||||
"max"
|
"max"
|
||||||
{:fn (fn [& numbers]
|
{:fn (fn [& numbers]
|
||||||
(if (coll? (first numbers))
|
(if (coll? (first numbers))
|
||||||
|
|
Reference in a new issue