Date: 11 February 2018
Version: 2.8.2
1 function.args
Add to project.clj
dependencies:
[zcaudate/hara.function.args "2.8.2"]
hara.function.args allow reasoning on the arguments of clojure methods
arg-check ^
counts the number of non-varidic argument types
(arg-check (fn [x]) 1) => true
(arg-check (fn [x & xs]) 1) => true
(arg-check (fn [x & xs]) 0)
=> (throws Exception "Function must accomodate 0 arguments")
arg-count ^
counts the number of non-varidic argument types
(arg-count (fn [x])) => [1]
(arg-count (fn [x & xs])) => []
(arg-count (fn ([x]) ([x y]))) => [1 2]
op ^
loose version of apply. Will adjust the arguments to put into a function
(op + 1 2 3 4 5 6) => 21
(op (fn [x] x) 1 2 3) => 1
(op (fn [_ y] y) 1 2 3) => 2
(op (fn [_] nil)) => (throws Exception)
varg-count ^
counts the number of arguments types before variable arguments
(varg-count (fn [x y & xs])) => 2
(varg-count (fn [x])) => nil
vargs? ^
checks that function contain variable arguments
(vargs? (fn [x])) => false
(vargs? (fn [x & xs])) => true
2 function.dispatch
Add to project.clj
dependencies:
[zcaudate/hara.function.dispatch "2.8.2"]
hara.function.dispatch allows alternative ways of calling a function
call ^
executes `(f v1 ... vn)` if `f` is not nil
(call nil 1 2 3) => nil
(call + 1 2 3) => 6
msg ^
message dispatch for object orientated type calling convention.
(def obj {:a 10
:b 20
:get-sum (fn [this]
(+ (:b this) (:a this)))})
(msg obj :get-sum) => 30