Utility functions used internally in Tornado.
Utility functions used internally in Tornado.
(->fixed x)
(->fixed x d)
Rounds a given number x to d decimal digits, or 0 by default.
Rounds a given number x to d decimal digits, or 0 by default.
(apply-avg coll)
Same as (apply average coll)
Same as (apply average coll)
(average & args)
Computes the average of 1 or more numbers. Accepts elements directly, use apply-avg for a sequence..
Computes the average of 1 or more numbers. Accepts elements directly, use apply-avg for a sequence..
(between value n1 n2)
Returns true if value is smaller than or equal n1 and greater than or equal n2.
Returns true if value is smaller than or equal n1 and greater than or equal n2.
(cartesian-product & seqs)
Given any number of seqs, this function returns a lazy sequence of all possible combinations of taking 1 element from each of the input sequences.
Given any number of seqs, this function returns a lazy sequence of all possible combinations of taking 1 element from each of the input sequences.
(conjv vect value)
Equal to (conj (vec vect) value).
Equal to (conj (vec vect) value).
A precalculated map for very fast conversions of hexadecimal strings in format "xx" to base10 numbers.
A precalculated map for very fast conversions of hexadecimal strings in format "xx" to base10 numbers.
(double-hex? str-expr)
Returns true if every 2-characters substring of the given string expression matches to the hexadecimal characters.
Returns true if every 2-characters substring of the given string expression matches to the hexadecimal characters.
(get-str-form x)
If the argument is a symbol, a keyword or a string, returns its string form. Otherwise, returns nil.
If the argument is a symbol, a keyword or a string, returns its string form. Otherwise, returns nil.
(in-range val min-val max-val)
If the value is not in range of min-val and max-val, returns the value of the corresponding border which is nearer to the value, otherwise returns the value.
If the value is not in range of min-val and max-val, returns the value of the corresponding border which is nearer to the value, otherwise returns the value.
(int* x)
Converts a float to an integer if the value would remain equal. Ratios will be converted to a float, or, again, to an integer if possible.
Converts a float to an integer if the value would remain equal. Ratios will be converted to a float, or, again, to an integer if possible.
(percent->number value)
(percent->number value throw-if-no-match)
If the argument is a value in percent, convert it to a corresponding numeral value. Throws an exception if the optional 2nd argument has a truthy value and the input type is none of string, number or CSSUnit instance. Otherwise thís function does not do anything and will return the input.
(percent->int 0.5) => 0.5
(percent->int "75%") ; can be "75 %" as well => 0.75
(percent->int (tornado.units/percent 35)) => 0.35
If the argument is a value in percent, convert it to a corresponding numeral value. Throws an exception if the optional 2nd argument has a truthy value and the input type is none of string, number or CSSUnit instance. Otherwise thís function does not do anything and will return the input. (percent->int 0.5) => 0.5 (percent->int "75%") ; can be "75 %" as well => 0.75 (percent->int (tornado.units/percent 35)) => 0.35
(percent-with-symbol-append value)
Multiplies a number with 100 to get a percentage value of it. Returns a string form of it with "%" appended. Non-numbers are returned unaffected.
Multiplies a number with 100 to get a percentage value of it. Returns a string form of it with "%" appended. Non-numbers are returned unaffected.
(prune-nils m)
Given a map, removes all keys having nil value. If the pruned map is empty, returns nil.
Given a map, removes all keys having nil value. If the pruned map is empty, returns nil.
(round x)
Rounds a given number to 4 decimal digits, which should be enough in most cases.
Rounds a given number to 4 decimal digits, which should be enough in most cases.
(some-instance? expr & instances)
Returns true if the expression is an instance of any of the instances.
Returns true if the expression is an instance of any of the instances.
(str-butlast s)
Returns the given string without the last character.
Returns the given string without the last character.
(to-percent-float value)
Parses a percentage from a string or multiplies a number with 100 to get a percentage value of it: (tpf "12%") => 12 (tpf "3") => 300 (tpf 8) => 800
Parses a percentage from a string or multiplies a number with 100 to get a percentage value of it: (tpf "12%") => 12 (tpf "3") => 300 (tpf 8) => 800
(toLower c)
Characters [A-F] will be transformed to [a-f], other chars will be returned unchanged.
Characters [A-F] will be transformed to [a-f], other chars will be returned unchanged.
(valid? x)
Returns true if the argument is a symbol, a keyword or a string.
Returns true if the argument is a symbol, a keyword or a string.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close