Suppose I have a record that is "function-like", at least in the sense that it represents an operation that could be applied to some arguments.
I can make it work as a function by implementing clojure.lang.IFn
, something like:
(defrecord Func [f x]
clojure.lang.IFn
(invoke [this arg]
(f x arg))
(applyTo [this args]
(apply f x args)))
((->Func + 7) 1)
=> 8
(yes I know that I've just reimplemented an inferior version of partial
.... it's just an example :-) )
Is making a record implement clojure.lang.IFn
a good practice or not?
Any pitfalls to this approach?
clojure.lang.Associative
but notclojure.lang.IFn
. So you can do(:a some-record)
to look up the keyword but not(some-record :x)
– Migratory