Liking cljdoc? Tell your friends :D

systems.thoughtfull.desiderata


defrecordcljmacro

(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. Another somewhat minor addition, metadata on the name symbol is propagated to the factory functions. 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 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

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.  Another somewhat
minor addition, metadata on the name symbol is propagated to the factory functions.  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`
sourceraw docstring

set-default-uncaught-exception-handler-fn!clj

(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*
sourceraw docstring

thread-factoryclj

(thread-factory &
                {:keys [name convey-bindings? priority daemon?
                        uncaught-exception-handler-fn
                        inherit-inheritable-thread-locals?]})

Create java.util.concurrent.ThreadFactory.

  • name (optional) — 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? (optional) — if true convey to created threads the bindings established when the thread factory was created, defaults to false.
  • priority (optional) — initial thread priority for created threads, defaults to Thread/NORMAL_PRIORITY.
  • daemon? (optional) — if true threads should be marked as daemon threads, defaults to false.
  • uncaught-exception-handler-fn (optional) — function to set as a Thread.UncaughtExceptionHandler after adapting with uncaught-exception-handler. Bindings established when the thread factory is created are conveyed to uncaught-exception-handler-fn.
  • inherit-inheritable-thread-locals? (optional) — 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`** (optional) — 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?`** (optional) — if true convey to created threads the bindings established
  when the thread factory was created, defaults to false.
- **`priority`** (optional) — initial thread priority for created threads, defaults to
  *Thread/NORMAL_PRIORITY*.
- **`daemon?`** (optional) — if true threads should be marked as daemon threads, defaults to
  false.
- **`uncaught-exception-handler-fn`** (optional) — function to set as a
  *Thread.UncaughtExceptionHandler* after adapting with [[uncaught-exception-handler]].  Bindings
  established when the thread factory is created are conveyed to `uncaught-exception-handler-fn`.
- **`inherit-inheritable-thread-locals?`** (optional) — 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*
sourceraw docstring

uncaught-exception-handlerclj

(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*
sourceraw docstring

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

× close