(boxed f x)Transform the quantity's number by any fn (i.e., fmap on the quantity-functor). Also works for numbers.
Beware:
Transform the quantity's number by any fn (i.e., fmap on the quantity-functor). Also works for numbers. Beware: 1. The return value is not checked, and quantities with non-numeric values will cause parts of Broch to break. 2. In cljs, broch quantities will sometimes have a ratio number type that is not a regular js Number. These will fail with clojure.core arithmetic ops (+, -, *, /), so use the ops from broch.core instead.
(compatible-units quantity)Returns unit-quantities with the same measure as the given quantity.
Returns unit-quantities with the same measure as the given quantity.
(composition q)The composition of this quantity.
The composition of this quantity.
(defunit unit-fn-name measure symb scale-or-comp)(defunit unit-fn-name measure symb scaling composition)Can be used to define units, but it's not compatible with cljs. Alternatively use the form this expands to: (def unit-fn-name (new-unit measure symbol scaling composition))
Can be used to define units, but it's not compatible with cljs. Alternatively use the form this expands to: (def unit-fn-name (new-unit measure symbol scaling composition))
(defunit-once unit-fn-name measure symb scale-or-comp)(defunit-once unit-fn-name measure symb scaling composition)Can be used to define units, but it's not compatible with cljs. Alternatively use the form this expands to: (defonce unit-fn-name (new-unit measure symbol scaling composition))
Can be used to define units, but it's not compatible with cljs. Alternatively use the form this expands to: (defonce unit-fn-name (new-unit measure symbol scaling composition))
(equivalent-quantities quantity)Returns quantities with compatible units equivalent to the given one.
Returns quantities with compatible units equivalent to the given one.
(measure q)The measure this quantity measures.
The measure this quantity measures.
(measure->symbols m)All registered unit symbols for the measure m.
All registered unit symbols for the measure m.
(new-unit measure symb scale-or-comp)(new-unit measure symb scaling composition)Register a new type of unit with the given measure, symbol, composition and/or scaling. Returns a fn (fn [number]) that creates a quantity of this unit.
Register a new type of unit with the given measure, symbol, composition and/or scaling. Returns a fn (fn [number]) that creates a quantity of this unit.
(nicest quantity)(nicest quantity unit-options)Returns the quantity converted to the "nicest" compatible unit for printing.
"nicest" being defined as the one with the shortest printed number, preferring precise doubles to ratios if available (as ratios can be harder to read).
The 1-arity implementation uses all compatible units as options. This is not recommended for most cases, as Broch includes some "weird" units that are often unwanted.
Example: (b/nicest (b/meters 18520)) => #broch/quantity[10 "NM"] ; nautical miles may be unwanted (b/nicest (b/meters 18520) [b/meters b/kilometers]) => #broch/quantity[18.52 "km"]
Returns the quantity converted to the "nicest" compatible unit for printing. "nicest" being defined as the one with the shortest printed number, preferring precise doubles to ratios if available (as ratios can be harder to read). The 1-arity implementation uses all compatible units as options. This is not recommended for most cases, as Broch includes some "weird" units that are often unwanted. Example: (b/nicest (b/meters 18520)) => #broch/quantity[10 "NM"] ; nautical miles may be unwanted (b/nicest (b/meters 18520) [b/meters b/kilometers]) => #broch/quantity[18.52 "km"]
(num q)Get just the number value of a quantity. Pass through if already a number.
Get just the number value of a quantity. Pass through if already a number.
(quantity unit x)Makes a new quantity of unit and x.
unit must be either a string representing a registered unit symbol or a quantity type.
x must be number-ish, i.e. a number, string of a number, or another quantity.
If x is a string, it's read with clojure.core/read-string and throws if it's not a number.
(Do not use this on raw user input, since it won't read localized numbers with different decimal marks correctly, like "12,1")
If x is another quantity, it will be converted (or throw exception if incompatible).
Makes a new quantity of unit and x. `unit` must be either a string representing a registered unit symbol or a quantity type. `x` must be number-ish, i.e. a number, string of a number, or another quantity. If x is a string, it's read with `clojure.core/read-string` and throws if it's not a number. (Do not use this on raw user input, since it won't read localized numbers with different decimal marks correctly, like "12,1") If x is another quantity, it will be converted (or throw exception if incompatible).
(registered-measures)All registered measures
All registered measures
(registered-unit-symbols)All registered unit symbols
All registered unit symbols
(standard-unit m)The standard unit symbol for the measure m.
Defined as the unit with a :broch/scaled of 1 in its composition map. Normally an SI-unit or a non-scaled composition of SI-units. Returns nil if m is unknown or no unscaled unit is defined.
The standard unit symbol for the measure m. Defined as the unit with a :broch/scaled of 1 in its composition map. Normally an SI-unit or a non-scaled composition of SI-units. Returns nil if m is unknown or no unscaled unit is defined.
(symbol q)The unit symbol for this quantity.
The unit symbol for this quantity.
(symbol->composition unit-symbol)All registered unit symbols for the measure m.
All registered unit symbols for the measure m.
(symbol->measure unit-symbol)The measure of a registered unit symbol. Returns nil if the symbol is unknown.
The measure of a registered unit symbol. Returns nil if the symbol is unknown.
(with-num quantity n)Make copy of a quantity with a different number.
Make copy of a quantity with a different number.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs | 
| ← | Move to previous article | 
| → | Move to next article | 
| Ctrl+/ | Jump to the search field |