(as-pack pack v)
assert-pack based on a test like as-pack?
assert-pack based on a test like as-pack?
(as-pack? pack v)
Accepts a pack map and any other value and returns true if the value meets the specifications of the provided pack. Note that a map might have additional keys not specified in the pack, and they are ignored. Use is-pack? to additionally require that only the pack's keys are included in the provided value.
Accepts a pack map and any other value and returns true if the value meets the specifications of the provided pack. Note that a map might have additional keys not specified in the pack, and they are ignored. Use is-pack? to additionally require that *only* the pack's keys are included in the provided value.
(assert-pack pack v explain-fn)
Used by the as-pack and is-pack macros; should not be called directly. Similar to the two-arity version of assistant.asserts/as macro, but instead of a predicate function, a pack map is supplied, which is just an ordinary map (as describe at top). When assert is on, it will assert that the value passes as if by as-pack? or is-pack? depending on explain-fn, and then return it. If it does not pass, the assertion failure shows the offending paths to keys and their values. If assert is off, as-pack does nothing and just passes through the value.
Used by the as-pack and is-pack macros; should not be called directly. Similar to the two-arity version of assistant.asserts/as macro, but instead of a predicate function, a pack map is supplied, which is just an ordinary map (as describe at top). When *assert* is on, it will assert that the value passes as if by as-pack? or is-pack? depending on explain-fn, and then return it. If it does not pass, the assertion failure shows the offending paths to keys and their values. If *assert* is off, as-pack does nothing and just passes through the value.
(defpack packname packmap)
This is a convenience macro that generates 3 defs at once. Even if you don't need all the defined functions, it can be more clear to explicitly show that the map you are creating will be used as a pack.
For example:
(defpack toy {:minimum-age pos? :color keyword?})
Will create the following:
(def toy {:minimum-age pos? :color keyword?}) (defn as-toy? [v] (as-pack? toy v)) (defn is-toy? [v] (is-pack? toy v))
It will not create new macros. Because macros which emit other defmacros are tasks reserved for others. (hint: ClojureScript files are supported; you can write a defpack in cljs source.)
This is a convenience macro that generates 3 defs at once. Even if you don't need all the defined functions, it can be more clear to explicitly show that the map you are creating will be used as a pack. For example: (defpack toy {:minimum-age pos? :color keyword?}) Will create the following: (def toy {:minimum-age pos? :color keyword?}) (defn as-toy? [v] (as-pack? toy v)) (defn is-toy? [v] (is-pack? toy v)) It will not create new macros. Because macros which emit other defmacros are tasks reserved for others. (hint: ClojureScript files are supported; you can write a defpack in cljs source.)
(defpacked packname packmap)
Creates a defpack and also a map of default values conforming to the pack spec. This accepts a map where each value must be a vector of a predicate function, as would be provided for keys in defpack, and a default value for that predicate. The ordinary defpack using only the predicates will be generated, with the optional 'true' argument to defpack which creates additional convenience functions (see doc on defpack), as well as a map of the same keys to the default values, with the name of the pack followed by -defaults.
For example, (defpacked vintage {:age [int? 0] :color [#{:blue :red} :blue]}) will create vars 'vintage' and 'vintage-defaults' and 'is-vintage?' and 'as-vintage?'.
As a convenience, the macro will call (is-pack vintage vintage-defaults) after creating these to ensure the defaults are valid.
Creates a defpack and also a map of default values conforming to the pack spec. This accepts a map where each value must be a vector of a predicate function, as would be provided for keys in defpack, and a default value for that predicate. The ordinary defpack using only the predicates will be generated, with the optional 'true' argument to defpack which creates additional convenience functions (see doc on defpack), as well as a map of the same keys to the default values, with the name of the pack followed by -defaults. For example, (defpacked vintage {:age [int? 0] :color [#{:blue :red} :blue]}) will create vars 'vintage' and 'vintage-defaults' and 'is-vintage?' and 'as-vintage?'. As a convenience, the macro will call (is-pack vintage vintage-defaults) after creating these to ensure the defaults are valid.
(explain-pack pack v)
This is used by as-pack and is-pack macros to provide helpful assertion errors. Probably does not need to be called directly, though it could be. Returns a map of :invalid and :extra vectors, each which contains k/v vector pairs from the provided value that do not meet the specification of the pack map. The :invalid and :extra vectors might be empty, but never nil. :invalid means the values do not pass the pack's predicates. :extra shows the additional entries not covered by the pack. Nested packs are tested and :invalid and :extra may contain nested vectors which act as paths to the nested keys and values that failed the pack specification.
This is used by as-pack and is-pack macros to provide helpful assertion errors. Probably does not need to be called directly, though it could be. Returns a map of :invalid and :extra vectors, each which contains k/v vector pairs from the provided value that do not meet the specification of the pack map. The :invalid and :extra vectors might be empty, but never nil. :invalid means the values do not pass the pack's predicates. :extra shows the additional entries not covered by the pack. Nested packs are tested and :invalid and :extra may contain nested vectors which act as paths to the nested keys and values that failed the pack specification.
(explained-as-pack? explanation)
Receives an explanation from explain-pack and returns true if there are no invalid keys.
Receives an explanation from explain-pack and returns true if there are no invalid keys.
(explained-is-pack? explanation)
Receives an explanation from explain-pack and returns true if there are no invalid keys and no extra keys.
Receives an explanation from explain-pack and returns true if there are no invalid keys and no extra keys.
(explanation? {:keys [invalid extra] :as explanation})
A pack explanation is outlined in explain-pack, and this function checks that the explanation is in the correct format.
A pack explanation is outlined in explain-pack, and this function checks that the explanation is in the correct format.
(is-pack pack v)
assert-pack based on a test like is-pack?
assert-pack based on a test like is-pack?
(is-pack? pack v)
Returns true if as-pack? is true and there are no additional keys in provided value.
Returns true if as-pack? is true and there are no additional keys in provided value.
(make-defaults-map m)
Makes the map of default values from the map provided to defpacked.
Makes the map of default values from the map provided to defpacked.
(make-defpack-map m)
Makes the map for passing to defpack from the map provided to defpacked.
Makes the map for passing to defpack from the map provided to defpacked.
(no-extra-keys? pack v)
Returs false if value v has keys that the pack does not
Returs false if value v has keys that the pack does not
(pack? pack v compare-keys)
Primarily used by as-pack? and is-pack?, this accepts a pack, a value to test, and a boolean compare-keys. If compare-keys is true, the test will also use no-extra-keys?
Primarily used by as-pack? and is-pack?, this accepts a pack, a value to test, and a boolean compare-keys. If compare-keys is true, the test will also use no-extra-keys?
(valid-defpacked-map? m)
Determines if provided map is in the structure expected by defpacked.
Determines if provided map is in the structure expected by defpacked.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close