memfn

added
1.0

ns
clojure.core

type
macro

(memfn name & args)

Expands into code that creates a fn that expects to be passed an
object and any args and calls the named instance method on the
object passing the args. Use when you want to treat a Java method as
a first-class fn. name may be type-hinted with the method receiver's
type in order to avoid reflective calls.

                user=> (def *files* (file-seq (java.io.File. "/tmp/")))
#'user/*files*
user=> (count (filter (memfn isDirectory) *files*))
68
user=> (count (filter #(.isDirectory %) *files*))
68

            
                user=> ;; you must pass arguments to your method to add up to the expected arity

user=> (def starts-with (memfn startsWith prefix))
#'user/starts-with
user=> (starts-with "pikachu" "pika")
true
user=> (starts-with "pikachu" "bulba")
false