Turn arbitrary Java objects into lazy maps, see extend-lazy-map
.
Turn arbitrary Java objects into lazy maps, see [[extend-lazy-map]].
(enum-to-keyword enum)
Return a keyword representation of an Enum object. Lowercase the Enum's name and replace _ with -.
Return a keyword representation of an Enum object. Lowercase the Enum's name and replace _ with -.
(extend-lazy-map class
&
{:keys [exclude post-fns keyname allow-impure
catch-exceptions]})
Extend [[to-lazy-map]] for converting an object of class
.
This macro must be used once on the class name, such as:
(extend-lazy-map String)
.
From then on, the to-lazy-map
function can be used to convert an
object of that class to a lazy map, where each entry correponds to a
method call. Since everything is lazy, you can rest assured the
methods won’t actually be called until you use them. The map keys
are keywords generated from the method names with symbol-to-keyword
.
For instance:
user> (to-lazy-map "My Own Map!")
{:to-char-array #<LazyVal lazy_map.core.LazyVal@7da41d83>,
:empty? #<LazyVal lazy_map.core.LazyVal@46e7f2eb>,
:to-string #<LazyVal lazy_map.core.LazyVal@1b155784>,
:intern #<LazyVal lazy_map.core.LazyVal@63f1f826>,
:chars #<LazyVal lazy_map.core.LazyVal@3e64b9de>,
:class #<LazyVal lazy_map.core.LazyVal@47ed7453>,
:length #<LazyVal lazy_map.core.LazyVal@76f5a25d>,
:trim #<LazyVal lazy_map.core.LazyVal@1a29446d>,
:bytes #<LazyVal lazy_map.core.LazyVal@118a4bf>,
:code-points #<LazyVal lazy_map.core.LazyVal@2d7b1723>,
:to-lower-case #<LazyVal lazy_map.core.LazyVal@76c7af9b>,
:hash-code #<LazyVal lazy_map.core.LazyVal@269d9702>,
:object #<LazyVal lazy_map.core.LazyVal@62e4e232>,
:to-upper-case #<LazyVal lazy_map.core.LazyVal@17533342>}
user> (:to-upper-case (to-lazy-map "My Own Map!"))
"MY OWN MAP!"
This macro also accepts a number of keyword arguments:
exclude
is a sequence of methods to avoid (methods with non-zero
arity or which return void are automatically avoided).post-fns
is a map from method names to functions. The function is
called on the return value of that method. If the method's return
value is an Enum, then this defaults to symbol-to-keyword
.keyname
is a map from method names to keys, these keys are used in
place of the one generated by symbol-to-keyword
.allow-impure
is a boolean. By default, methods which return void
are automatically avoided. Setting this to true disables that
precaution.catch-exceptions
is a boolean which indicates to catch and discard
any exceptions thrown by the methods (and return nil).Extend [[to-lazy-map]] for converting an object of `class`. This macro must be used once on the class name, such as: `(extend-lazy-map String)`. From then on, the `to-lazy-map` function can be used to convert an object of that class to a lazy map, where each entry correponds to a method call. Since everything is lazy, you can rest assured the methods won’t actually be called until you use them. The map keys are keywords generated from the method names with [[symbol-to-keyword]]. For instance: ```clojure user> (to-lazy-map "My Own Map!") {:to-char-array #<LazyVal lazy_map.core.LazyVal@7da41d83>, :empty? #<LazyVal lazy_map.core.LazyVal@46e7f2eb>, :to-string #<LazyVal lazy_map.core.LazyVal@1b155784>, :intern #<LazyVal lazy_map.core.LazyVal@63f1f826>, :chars #<LazyVal lazy_map.core.LazyVal@3e64b9de>, :class #<LazyVal lazy_map.core.LazyVal@47ed7453>, :length #<LazyVal lazy_map.core.LazyVal@76f5a25d>, :trim #<LazyVal lazy_map.core.LazyVal@1a29446d>, :bytes #<LazyVal lazy_map.core.LazyVal@118a4bf>, :code-points #<LazyVal lazy_map.core.LazyVal@2d7b1723>, :to-lower-case #<LazyVal lazy_map.core.LazyVal@76c7af9b>, :hash-code #<LazyVal lazy_map.core.LazyVal@269d9702>, :object #<LazyVal lazy_map.core.LazyVal@62e4e232>, :to-upper-case #<LazyVal lazy_map.core.LazyVal@17533342>} user> (:to-upper-case (to-lazy-map "My Own Map!")) "MY OWN MAP!" ``` This macro also accepts a number of keyword arguments: - `exclude` is a sequence of methods to avoid (methods with non-zero arity or which return void are automatically avoided). - `post-fns` is a map from method names to functions. The function is called on the return value of that method. If the method's return value is an Enum, then this defaults to [[symbol-to-keyword]]. - `keyname` is a map from method names to keys, these keys are used in place of the one generated by [[symbol-to-keyword]]. - `allow-impure` is a boolean. By default, methods which return void are automatically avoided. Setting this to true disables that precaution. - `catch-exceptions` is a boolean which indicates to catch and discard any exceptions thrown by the methods (and return nil).
(symbol-to-keyword method)
Convert a method or field name to a keyword. If the name starts with "is", the "is" is removed and a "?" is appended to the end. If the name starts with "get", the "get" is removed.
Examples: toString :to-string isPerson :person? hasKindness :has-kindness getPrice :price
Convert a method or field name to a keyword. If the name starts with "is", the "is" is removed and a "?" is appended to the end. If the name starts with "get", the "get" is removed. Examples: toString :to-string isPerson :person? hasKindness :has-kindness getPrice :price
Turn argument to a LazyMap. Just Return it if already a map (lazy or otherwise).
Turn argument to a LazyMap. Just Return it if already a map (lazy or otherwise).
(to-lazy-map o)
Convert a Java object to a lazy map, where each entry corresponds to a method call.
Convert a Java object to a lazy map, where each entry corresponds to a method call.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close