(defrecord name docstring? [& fields] & opts+specs)
Drop-in replacement for clojure.core/defrecord
with extra functionality. See
clojure.core/defrecord
for details about core functionality.
As a relatively minor addition the factory function takes keyword arguments. There are three other additions: a docstring, default values, and an initializer.
A docstring, if given, is appended to the docstring for both the factory and positional factory functions.
Example:
user> (desiderata/defrecord Widget
"A widget for frobbing gizmos.
width and height are in metric."
[width height])
user.Widget
user> (doc map->Widget)
-------------------------
user/map->Widget
([& {:keys [width height]}])
Factory function for class user.Widget, taking a map of keywords to field values.
A widget for frobbing gizmos.
width and height are in metric.
nil
The :systems.thoughtfull.desiderata/defaults
option can be given with a hash map to supply
defaults. The hash map supplies default values for the declared fields (and extra non-field
keys and values). Any values given as arguments to the factory or positional factory functions
override these defaults.
Example:
user> (desiderata/defrecord Gizmo
[name]
::desiderata/defaults
{:name "Gizmo"
:color :blue})
user.Gizmo
user> (->Gizmo "the Great")
{:name "the Great", :color :blue}
user> (map->Gizmo :texture :bumpy)
{:name "Gizmo", :color :blue, :texture :bumpy}
If a method with the same name as the defrecord is defined, it is used to as an initializer. After the record is constructed by the factory or positional factory function, it is given to the initializer and the result is returned from the factory or positional factory function. If the initializer does not return an instance of the type, an IllegalStateException is thrown.
Example:
user> (desiderata/defrecord Company
[debt equity]
(Company
[this]
(assoc this :gearing-ratio (/ debt equity))))
user.Company
user> (->Company 100 1000)
{:debt 100, :equity 1000, :gearing-ratio 1/10}
name
— name of the typedocstring
(optional) — appended to the docstrings of the factory and positional factory
functionsfields
— names of the fields of the typeopts+specs
(optional) — options, interfaces, and methodsSee clojure.core/defrecord
Drop-in replacement for `clojure.core/defrecord` with extra functionality. See `clojure.core/defrecord` for details about core functionality. As a relatively minor addition the factory function takes keyword arguments. There are three other additions: a docstring, default values, and an initializer. A docstring, if given, is appended to the docstring for both the factory and positional factory functions. Example: ```clojure user> (desiderata/defrecord Widget "A widget for frobbing gizmos. width and height are in metric." [width height]) user.Widget user> (doc map->Widget) ------------------------- user/map->Widget ([& {:keys [width height]}]) Factory function for class user.Widget, taking a map of keywords to field values. A widget for frobbing gizmos. width and height are in metric. nil ``` The `:systems.thoughtfull.desiderata/defaults` option can be given with a hash map to supply defaults. The hash map supplies default values for the declared fields (and extra non-field keys and values). Any values given as arguments to the factory or positional factory functions override these defaults. Example: ```clojure user> (desiderata/defrecord Gizmo [name] ::desiderata/defaults {:name "Gizmo" :color :blue}) user.Gizmo user> (->Gizmo "the Great") {:name "the Great", :color :blue} user> (map->Gizmo :texture :bumpy) {:name "Gizmo", :color :blue, :texture :bumpy} ``` If a method with the same name as the defrecord is defined, it is used to as an initializer. After the record is constructed by the factory or positional factory function, it is given to the initializer and the result is returned from the factory or positional factory function. If the initializer does not return an instance of the type, an _IllegalStateException_ is thrown. Example: ```clojure user> (desiderata/defrecord Company [debt equity] (Company [this] (assoc this :gearing-ratio (/ debt equity)))) user.Company user> (->Company 100 1000) {:debt 100, :equity 1000, :gearing-ratio 1/10} ``` - **`name`** — name of the type - **`docstring`** (optional) — appended to the docstrings of the factory and positional factory functions - **`fields`** — names of the fields of the type - **`opts+specs`** (optional) — options, interfaces, and methods See `clojure.core/defrecord`
(binding-conveying-thread-factory? this)
true if this is a ThreadFactory that will convey bindings.
true if this is a _ThreadFactory_ that will convey bindings.
(set-default-uncaught-exception-handler-fn! uncaught-exception-handler-fn)
Set default Thread.UncaughtExceptionHandler to uncaught-exception-handler-fn
after adapting
it using uncaught-exception-handler
. uncaught-exception-handler-fn
should be a function
of two arguments (thread and throwable). If uncaught-exception-handler-fn
is nil, then the
default uncaught exception handler is cleared.
uncaught-exception-handler-fn
— function of two arguments (thread and throwable) to set
as the default Thread.UncaughtExceptionHandler after adapting it using
uncaught-exception-handler
. Returns nil if uncaught-exception-handler-fn
is nil.See Thread/setDefaultUncaughtExceptionHandler, Thread.UncaughtExceptionHandler
Set default _Thread.UncaughtExceptionHandler_ to `uncaught-exception-handler-fn` after adapting it using [[uncaught-exception-handler]]. `uncaught-exception-handler-fn` should be a function of two arguments (thread and throwable). If `uncaught-exception-handler-fn` is nil, then the default uncaught exception handler is cleared. - **`uncaught-exception-handler-fn`** — function of two arguments (thread and throwable) to set as the default _Thread.UncaughtExceptionHandler_ after adapting it using [[uncaught-exception-handler]]. Returns nil if `uncaught-exception-handler-fn` is nil. See _Thread/setDefaultUncaughtExceptionHandler_, _Thread.UncaughtExceptionHandler_
(thread-factory &
{:as options
:keys [name convey-bindings? priority daemon?
uncaught-exception-handler-fn
inherit-inheritable-thread-locals?]})
Create java.util.concurrent.ThreadFactory.
name
— prefix for thread names, e.g., a name
of "widget-pool"
will create
threads named "widget-pool-thread-N"
where N increments each time a thread is created. If
name
is not given, it defaults to "pool-M"
where M is incremented for each new thread
factory.convey-bindings?
— if true convey bindings to created threads and
uncaught-exception-handler-fn
, defaults to true.priority
— initial thread priority for created threads, defaults to
Thread/NORMAL_PRIORITY.daemon?
— if true threads should be marked as daemon threads, defaults to false.uncaught-exception-handler-fn
— function to set as a Thread.UncaughtExceptionHandler
after adapting with uncaught-exception-handler
.inherit-inheritable-thread-locals?
— if true, then new threads inherit initial values
for InheritableThreadLocal from constructing thread, defaults to true. See
java.util.Thread/new.See java.util.concurrent.ThreadFactory, Thread.UncaughtExceptionHandler
Create *java.util.concurrent.ThreadFactory*. - **`name`** — prefix for thread names, e.g., a `name` of `"widget-pool"` will create threads named `"widget-pool-thread-N"` where N increments each time a thread is created. If `name` is not given, it defaults to `"pool-M"` where M is incremented for each new thread factory. - **`convey-bindings?`** — if true convey bindings to created threads and `uncaught-exception-handler-fn`, defaults to true. - **`priority`** — initial thread priority for created threads, defaults to _Thread/NORMAL_PRIORITY_. - **`daemon?`** — if true threads should be marked as daemon threads, defaults to false. - **`uncaught-exception-handler-fn`** — function to set as a _Thread.UncaughtExceptionHandler_ after adapting with [[uncaught-exception-handler]]. - **`inherit-inheritable-thread-locals?`** — if true, then new threads inherit initial values for _InheritableThreadLocal_ from constructing thread, defaults to true. See _java.util.Thread/new_. See _java.util.concurrent.ThreadFactory_, _Thread.UncaughtExceptionHandler_
(uncaught-exception-handler uncaught-exception-handler-fn)
Adapt uncaught-exception-handler-fn
to a Thread.UncaughtExceptionHandler.
uncaught-exception-handler-fn
should be a function of two arguments (thread and
throwable). Returns nil if uncaught-exception-handler-fn
is nil.
uncaught-exception-handler-fn
— function of two arguments (thread and throwable) to
adapt as a Thread.UncaughtExceptionHandler. Returns nil if uncaught-exception-handler-fn
is
nil.See Thread.UncaughtExceptionHandler
Adapt `uncaught-exception-handler-fn` to a _Thread.UncaughtExceptionHandler_. `uncaught-exception-handler-fn` should be a function of two arguments (thread and throwable). Returns nil if `uncaught-exception-handler-fn` is nil. - **`uncaught-exception-handler-fn`** — function of two arguments (thread and throwable) to adapt as a _Thread.UncaughtExceptionHandler_. Returns nil if `uncaught-exception-handler-fn` is nil. See _Thread.UncaughtExceptionHandler_
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close