CrossClj

0.1.0 docs

SourceDocs



RECENT

    arity

    Clojars

    Apr 30, 2018


    Readme

    Index of all namespaces


    The README below is fetched from the published project artifact. Some relative links may be broken.

    arity

    Get and fake the arity of any Clojure function.

    Usage

    [arity "0.1.0"]
    

    arities

    ;; Defined functions
    (arities inc)                ;; => [1]
    (arities +)                  ;; => [0 1 2 ##Inf]
    (arities #'+)                ;; => [0 1 2 ##Inf]
    
    ;; Anonymous functions
    (arities (fn []))            ;; => [0]
    (arities (fn [a b & more]))  ;; => [##Inf]
    (arities (fn ([a]) ([a b]))) ;; => [1 2]
    
    ;; #(...) anonymous functions
    (arities #(apply + % %&))    ;; => [##Inf]
    (arities #(+ %1 %2))         ;; => [2]
    
    ;; Macros
    (arities #'->)               ;; => [##Inf]
    

    Comes with min-arity and max-arity.

    fake-arity

    (def f (constantly 1))
    (arities f)                    ;; => [##Inf]
    
    (arities (fake-arity 1 f))     ;; => [1]
    (arities (fake-arity [0 1] f)) ;; => [0 1] 
    

    fake-arity is completely orthogonal to Clojure’s native arity checks and its sole purpose is to force the return value of arities as well as min-arity and max-arity.

    License

    Copyright © 2018 TristeFigure

    Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.