Liking cljdoc? Tell your friends :D
Clojure only.

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. 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.

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:

(desiderata/defrecord Gizmo [name] ::desiderata/defaults {:name "Gizmo" :color :blue})

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 defrecord, an IllegalStateException is thrown. Example:

(desiderata/defrecord Company [debt equity] (Company [this] (assoc this :gearing-ratio (/ debt equity))))

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.

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:

(desiderata/defrecord Gizmo
  [name]
  ::desiderata/defaults {:name "Gizmo" :color :blue})

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 defrecord, an IllegalStateException is
thrown.  Example:

(desiderata/defrecord Company
  [debt equity]
  (Company
    [this]
    (assoc this :gearing-ratio (/ debt equity))))
sourceraw docstring

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

× close