ClojureDocs

Nav

Namespaces

fn?

clojure.core

Available since 1.0 (source)
  • (fn? x)
Returns true if x implements Fn, i.e. is an object created via fn.
2 Examples
user=> (fn? 5)
false
user=> (fn? inc)
true
user=> (fn? (fn []))
true
user=> (fn? #(5))
true
;; Even though maps, sets, vectors and keywords behave as functions:
user=> ({:a 1} :a)
1

;; fn? still returns false for them because they are not created using fn:
user=> (fn? {:a 1})
false
See Also

Returns true if x implements IFn. Note that many data structures (e.g. sets and maps) implement IF...

Added by mmwaikar
1 Note
    By , created 7.6 years ago

    Note fn? only tests if something was created using fn, not if it’s a function. Use ifn? for that. Some things are functions even though they weren’t created with fn, such as maps, vectors and keywords.