Liking cljdoc? Tell your friends :D

com.rpl.nippy-serializable-fn

This namespace custom freeze/thaw implementations that allow Clojure fns to be serialized with all the standard Nippy freeze/thaw fns.

Only a fn's internal class name and the objects in the closure are actually serialized. No code or bytecode is serialized. Both the freezing process and the thawing process must be running the same code, or the thaw operation can have undefined behavior.

A custom serializer / deserializer for each frozen/thawed fn type is generated upon first use, and then cached for future access, making it very efficient. (No reflection is required during steady state operation.) The cache can be cleared via the clear-cache fn; you typically only need to do this during interactive development.

To use this extension, just define fns like usual and then freeze instances to bytes:

(let [d 10 my-fn (fn [a b c] (+ a b c d))] (nippy/freeze! my-fn) ; => bytes )

The same instances can be thawed again later, and will reconstruct its closure as expected:

(let [d 10 my-fn (fn [a b c] (+ a b c d)) frozen-fn-bytes (nippy/freeze! my-fn) thawed-fn (nippy/thaw! frozen-fn-bytes)] (thawed-fn 1 2 3); => 16 )

Be careful about freezing fns that have 'big' stuff in their closure! All referenced objects will be recursively serialized. If an un-freezeable object is encountered, then it will cause an error.

This namespace custom freeze/thaw implementations that allow Clojure fns to
be serialized with all the standard Nippy freeze/thaw fns.

Only a fn's internal class name and the objects in the closure are actually
serialized. No code or bytecode is serialized. Both the freezing process and the
thawing process must be running the same code, or the thaw operation can have
undefined behavior.

A custom serializer / deserializer for each frozen/thawed fn type is generated
upon first use, and then cached for future access, making it very efficient.
(No reflection is required during steady state operation.) The cache can be
cleared via the `clear-cache` fn; you typically only need to do this during
interactive development.

To use this extension, just define fns like usual and then freeze instances to bytes:

`(let [d 10
       my-fn (fn [a b c] (+ a b c d))]
   (nippy/freeze! my-fn) ; => bytes
   )`

The same instances can be thawed again later, and will reconstruct its closure as expected:

`(let [d 10
       my-fn (fn [a b c] (+ a b c d))
       frozen-fn-bytes (nippy/freeze! my-fn)
       thawed-fn (nippy/thaw! frozen-fn-bytes)]
    (thawed-fn 1 2 3); => 16
   )`

Be careful about freezing fns that have 'big' stuff in their closure! All
referenced objects will be recursively serialized. If an un-freezeable object is
encountered, then it will cause an error.
raw docstring

*allow-anon-serialization*clj

source

clear-cacheclj

(clear-cache)

Clear all cached generated serializer and deserializer fns. You typically only need to do this if you've redefined a fn to include new vars in its closure during interactive development.

Clear all cached generated serializer and deserializer fns. You typically
only need to do this if you've redefined a fn to include new vars in its closure
during interactive development.
sourceraw docstring

method-handle-lookupclj

source

resolve-fn-varclj

(resolve-fn-var v)

When a fn is created via defn, the name of the fn class and the var that holds the fn instance are related and can be determined. In most cases, they are an almost exact match (modulo munging), except for:

  • when the fn has a closure, it'll have a gensym'd number at the end
  • when fn is evaluated in the repl, it'll include more or more '$eval' name segments that are not reflected in the var name
  • when the fn is a protocol method the class name must be retrieved via the methodImplCache
When a fn is created via defn, the name of the fn class and the var that holds
the fn instance are related and can be determined. In most cases, they are an
almost exact match (modulo munging), except for:
 * when the fn has a closure, it'll have a gensym'd number at the end
 * when fn is evaluated in the repl, it'll include more or more '$eval' name
   segments that are not reflected in the var name
 * when the fn is a protocol method the class name must be retrieved via the
   methodImplCache
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close