Liking cljdoc? Tell your friends :D

hara.function


applymcljmacro

(applym macro & args)

Allow macros to be applied to arguments just like functions

(applym const '((+ 1 2))) => 3

(macroexpand '(applym const '((+ 1 2)))) => 3

Allow macros to be applied to arguments just like functions

(applym const '((+ 1 2))) => 3

(macroexpand '(applym const '((+ 1 2))))
=> 3
raw docstring

arg-checkclj

(arg-check f num)
(arg-check f num message)

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")

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")
raw docstring

arg-countclj

(arg-count f)

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]

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]
raw docstring

callclj

(call obj)
(call obj f)
(call obj f v1)
(call obj f v1 v2)
(call obj f v1 v2 v3)
(call obj f v1 v2 v3 v4)
(call obj f v1 v2 v3 v4 & vs)

like invoke but reverses the function and first argument

(call 2) => 2

(call 2 + 1 2 3) => 8

like `invoke` but reverses the function and first argument

(call 2) => 2

(call 2 + 1 2 3) => 8
raw docstring

constcljmacro

(const body)

converts an expression into a constant at compile time

(const (+ 1 2)) => 3

(macroexpand '(const (+ 1 2))) => 3

converts an expression into a constant at compile time

(const (+ 1 2)) => 3

(macroexpand '(const (+ 1 2))) => 3
raw docstring

create-argsclj

(create-args [doc? attr? & more :as arglist])

caches the result of a function

(create-args '[[x] (inc x) nil nil]) => '("" {} [x] (inc x))

caches the result of a function

(create-args '[[x] (inc x) nil nil])
=> '("" {} [x] (inc x))
raw docstring

create-def-formclj

(create-def-form name attrs body)
(create-def-form name doc attrs arglist body)

removes a cached result

(create-def-form 'hello "doc" {:added "1.3"} '[x] '(inc x)) '(do (def hello (inc x)) (clojure.core/doto (var hello) (clojure.core/alter-meta! clojure.core/merge {:added "1.3"} {:arglists (quote ([x])), :doc "doc"})))

removes a cached result

(create-def-form 'hello "doc" {:added "1.3"} '[x] '(inc x))
'(do (def hello (inc x))
     (clojure.core/doto (var hello)
       (clojure.core/alter-meta! clojure.core/merge
                                 {:added "1.3"}
                                 {:arglists (quote ([x])), :doc "doc"})))
raw docstring

defcomposecljmacro

(defcompose name doc? attrs? & [arglist body])

used instead of def for functional composition

(defcompose -add-10- [x & more] (partial + 10))

(-add-10- 10) => 20

used instead of `def` for functional composition

(defcompose -add-10-
  [x & more]
  (partial + 10))

(-add-10- 10) => 20
raw docstring

defexecutivecljmacro

(defexecutive name doc? attrs? & [fields settings & body])

creates an executable data type

(declare hello-display hello-print)

(def hello-invoke (fn [this & args] (str (.name this) " " (apply + args))))

(defexecutive -Hello- [name place date] {:tag "hello" :invoke hello-invoke :display hello-display :print hello-print})

((-Hello-. "hello" nil nil) 1 2 3 4 5) => "hello 15"

creates an executable data type

(declare hello-display hello-print)

(def hello-invoke (fn [this & args]
                    (str (.name this) " " (apply + args))))

(defexecutive -Hello- [name place date]
  {:tag "hello"
   :invoke   hello-invoke
   :display  hello-display
   :print    hello-print})

((-Hello-. "hello" nil nil) 1 2 3 4 5)
=> "hello 15"
raw docstring

definvokecljmacro

(definvoke name doc? & [attrs? & [params & body :as more]])

customisable invocation forms

(definvoke -another- [:compose {:val (partial + 10) :arglists '([& more])}])

customisable invocation forms

(definvoke -another-
  [:compose {:val (partial + 10)
            :arglists '([& more])}])
raw docstring

deflookupcljmacro

(deflookup name doc? attrs? & [arglist lookup transfer?])

defines a map based lookup

(deflookup -country- [city] {:kunming :china :melbourne :australia})

(-country- :kunming) => :china

defines a map based lookup

(deflookup -country-
  [city]
  {:kunming :china
   :melbourne :australia})

(-country- :kunming) => :china
raw docstring

defmemoizecljmacro

(defmemoize name doc? attrs? & body)

defines a cached function

(defmemoize -dec- "decrements" {:added "1.0"} ([x] (dec x)))

(-dec- 1) => 0 @+-dec- => '{(1) 0}

defines a cached function

(defmemoize -dec-
  "decrements"
  {:added "1.0"}
  ([x] (dec x)))

(-dec- 1) => 0
@+-dec- => '{(1) 0}
raw docstring

fncljmacro

(fn & body)

macro for an extensible fn form

(fn [x] x) => fn?

^{:type :function} (fn [x] x) => java.util.function.Function

^{:type :predicate} (fn [x] true) => java.util.function.Predicate

macro for an extensible `fn` form

(fn [x] x)
=> fn?

^{:type :function}
(fn [x] x)
=> java.util.function.Function

^{:type :predicate}
(fn [x] true)
=> java.util.function.Predicate
raw docstring

form-applyclj

(form-apply form args)

Applies a list as a function to an argument vector

(form-apply '(+ 1 %1 %2) [2 3]) => 6

Applies a list as a function to an argument vector

(form-apply '(+ 1 %1 %2) [2 3]) => 6
raw docstring

form-arglistsclj

(form-arglists body)

returns the arglists of a form

(form-arglists '([x] x)) => '(quote ([x]))

(form-arglists '(([x] x) ([x y] (+ x y)))) => '(quote ([x] [x y]))

returns the arglists of a form

(form-arglists '([x] x))
=> '(quote ([x]))

(form-arglists '(([x] x) ([x y] (+ x y))))
=> '(quote ([x] [x y]))
raw docstring

form-evalclj

(form-eval form & args)

Evaluates a list as a functions and to a set of arguments.

(form-eval '(+ 1 %1 %2) 2 3) => 6

Evaluates a list as a functions and to a set of arguments.

(form-eval '(+ 1 %1 %2) 2 3) => 6
raw docstring

form-fnclj

(form-fn form)

Creates a function out of a list (def my-inc (form-fn '(+ 1 %)))

(my-inc 1) => 2 (meta my-inc) => {:source "#(+ 1 %)\n"}

Creates a function out of a list
(def my-inc (form-fn '(+ 1 %)))

(my-inc 1) => 2
(meta my-inc) => {:source "#(+ 1 %)\n"}
raw docstring

invokeclj

(invoke f)
(invoke f v1)
(invoke f v1 v2)
(invoke f v1 v2 v3)
(invoke f v1 v2 v3 v4)
(invoke f v1 v2 v3 v4 & vs)

Executes (f v1 ... vn) if f is not nil

(invoke nil 1 2 3) => nil

(invoke + 1 2 3) => 6

Executes `(f v1 ... vn)` if `f` is not nil

(invoke nil 1 2 3) => nil

(invoke + 1 2 3) => 6
raw docstring

list-patchedclj

(list-patched)

returns all functions that have been patched

(patch #'hara.core.base.check/double? hara.core.base.check/double?)

(-> (list-patched) (get #'hara.core.base.check/double?) boolean) => true

returns all functions that have been patched

(patch #'hara.core.base.check/double?
       hara.core.base.check/double?)

(-> (list-patched)
    (get #'hara.core.base.check/double?)
    boolean)
=> true
raw docstring

lookupclj

(lookup m)
(lookup m {:keys [in out not-found] :as transfer})

creates a lookup function based on a map lookup

(def -opts- {:in (fn [s] (-> s (.toLowerCase) keyword)) :out name :not-found :no-reference})

(def -lookup- (lookup {:kunming :china :melbourne :australia} -opts-))

(-lookup- "MeLBoURne") => "australia"

creates a lookup function based on a map lookup

(def -opts-
  {:in  (fn [s] (-> s (.toLowerCase) keyword))
   :out name
   :not-found :no-reference})

(def -lookup-
  (lookup {:kunming :china
           :melbourne :australia}
          -opts-))

(-lookup- "MeLBoURne") => "australia"
raw docstring

memoizeclj

(memoize function cache var)
(memoize function cache var registry status)

caches the result of a function (ns-unmap ns '+-inc-) (ns-unmap ns '-inc-) (def +-inc- (atom {})) (declare -inc-) (def -inc- (memoize inc +-inc- #'-inc-))

(-inc- 1) => 2 (-inc- 2) => 3

caches the result of a function
(ns-unmap *ns* '+-inc-)
(ns-unmap *ns* '-inc-)
(def +-inc- (atom {}))
(declare -inc-)
(def -inc-  (memoize inc +-inc- #'-inc-))

(-inc- 1) => 2
(-inc- 2) => 3
raw docstring

memoize-clearclj

(memoize-clear mem)

clears all results

(memoize-clear -inc-) => '{(2) 3}

clears all results

(memoize-clear -inc-)
=> '{(2) 3}
raw docstring

memoize-removeclj

(memoize-remove mem & args)

removes a cached result

(memoize-remove -inc- 1) => 2

removes a cached result

(memoize-remove -inc- 1)
=> 2
raw docstring

messageclj

(message obj kw)
(message obj kw v1)
(message obj kw v1 v2)
(message obj kw v1 v2 v3)
(message obj kw v1 v2 v3 v4)
(message obj kw v1 v2 v3 v4 & vs)

Message dispatch for object orientated type calling convention.

(def obj {:a 10 :b 20 :get-sum (fn [this] (+ (:b this) (:a this)))})

(message obj :get-sum) => 30

Message dispatch for object orientated type calling convention.

(def obj {:a 10
          :b 20
          :get-sum (fn [this]
                     (+ (:b this) (:a this)))})

(message obj :get-sum) => 30
raw docstring

multi-addclj

(multi-add multi dispatch-val method)

adds an entry to the multimethod

(multi-add world :c (fn [m] (assoc m :c 3))) => world

adds an entry to the multimethod

(multi-add world :c (fn [m] (assoc m :c 3)))
=> world
raw docstring

multi-cloneclj

(multi-clone source name)

creates a multimethod from an existing one

(defmulti hello :type)

(defmethod hello :a [m] (assoc m :a 1))

(def world (multi-clone hello "world"))

(defmethod world :b [m] (assoc m :b 2))

(world {:type :b}) => {:type :b :b 2}

;; original method should not be changed (hello {:type :b}) => (throws)

creates a multimethod from an existing one

(defmulti hello :type)

(defmethod hello :a
  [m] (assoc m :a 1))

(def world (multi-clone hello "world"))

(defmethod world :b
  [m] (assoc m :b 2))

(world {:type :b})
=> {:type :b :b 2}

;; original method should not be changed
(hello {:type :b})
=> (throws)
raw docstring

multi-getclj

(multi-get multi dispatch)

returns all entries in the multimethod

(multi-get world :b) => fn?

returns all entries in the multimethod

(multi-get world :b)
=> fn?
raw docstring

multi-has?clj

(multi-has? multi val)

returns true if the multimethod contains a value for dispatch

(multi-has? print-method Class) => true

returns `true` if the multimethod contains a value for dispatch

(multi-has? print-method Class)
=> true
raw docstring

multi-keysclj

(multi-keys multi)

returns all keys for a given multimethod

(multi-keys world) => #{:a :b}

returns all keys for a given multimethod

(multi-keys world)
=> #{:a :b}
raw docstring

multi-listclj

(multi-list multi)

returns all entries in the multimethod

(multi-list world) => (satisfies [:a :b] (comp vec sort keys))

returns all entries in the multimethod

(multi-list world)
=> (satisfies [:a :b]
              (comp vec sort keys))
raw docstring

multi-match?clj

(multi-match? multi method)
(multi-match? multi method throw?)

checks if the multi dispatch matches the arguments

(multi-match? (.dispatchFn string/-from-string) (fn [_ _ _])) => true

(multi-match? (.dispatchFn string/-from-string) (fn [_]) true) => (throws)

checks if the multi dispatch matches the arguments

(multi-match? (.dispatchFn string/-from-string) (fn [_ _ _]))
=> true

(multi-match? (.dispatchFn string/-from-string) (fn [_]) true)
=> (throws)
raw docstring

multi-removeclj

(multi-remove multi dispatch)

removes an entry

(multi-remove world :b) => fn?

removes an entry

(multi-remove world :b)
=> fn?
raw docstring

multi?clj

(multi? obj)

returns true if obj is a multimethod

(multi? print-method) => true

(multi? println) => false

returns `true` if `obj` is a multimethod

(multi? print-method) => true

(multi? println) => false
raw docstring

opclj

(op f & args)

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)

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)
raw docstring

patchclj

(patch var f)

patches the existing function with a given one

(patch #'hara.core.base.check/double? (fn [x] (instance? Float x)))

(hara.core.base.check/double? (float 1.0)) => true

patches the existing function with a given one

(patch #'hara.core.base.check/double?
       (fn [x]
         (instance? Float x)))

(hara.core.base.check/double? (float 1.0))
=> true
raw docstring

patched?clj

(patched? var)

checks if an existing function has been patched

(patched? #'hara.core.base.check/double?) => true

checks if an existing function has been patched

(patched? #'hara.core.base.check/double?)
=> true
raw docstring

unpatchclj

(unpatch var)

removes the patch creates for the var

(unpatch #'hara.core.base.check/double?)

(hara.core.base.check/double? (float 1.0)) => false

removes the patch creates for the var

(unpatch #'hara.core.base.check/double?)

(hara.core.base.check/double? (float 1.0))
=> false
raw docstring

varg-countclj

(varg-count f)

counts the number of arguments types before variable arguments

(varg-count (fn [x y & xs])) => 2

(varg-count (fn [x])) => nil

counts the number of arguments types before variable arguments

(varg-count (fn [x y & xs])) => 2

(varg-count (fn [x])) => nil
raw docstring

vargs?clj

(vargs? f)

checks that function contain variable arguments

(vargs? (fn [x])) => false

(vargs? (fn [x & xs])) => true

checks that function contain variable arguments

(vargs? (fn [x])) => false

(vargs? (fn [x & xs])) => true
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close