1.3.0 permalink Arrow_down_16x16

memfn

clojure.core

  • (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.

1 Example top

  • user=> (def *files* (file-seq (java.io.File. "/tmp/")))
    #'user/*files*
    user=> (count (filter (memfn isDirectory) *files*))
    68
    user=> (count (filter #(.isDirectory %) *files*))
    68
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:3412 top

(defmacro memfn
  "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."
  {:added "1.0"}
  [name & args]
  `(fn [target# ~@args]
     (. target# (~name ~@args))))
Vars in clojure.core/memfn:
Used in 0 other vars

Comments top

No comments for memfn. Log in to add a comment.