Random support functions and macros.
Random support functions and macros.
(ask &
{:keys [ask-fn allow-empty? empty-nil? empty-quits? empty-quits-nil? prompt
confirm-prompt not-match-msg empty-msg retries confirmation?]
:or {confirm-prompt "Repeat text: "
not-match-msg "Texts do not match."
empty-msg "Text is empty."
empty-nil? false
confirmation? true
empty-quits-nil? true
ask-fn read-line-with-prompt
prompt "Enter text: "
allow-empty? false
empty-quits? false}})
Ask user for a string with optional confirmation using ask-fn to get a string (or nil).
Repeats until two entered strings are the same and are not empty.
Keyword arguments can be given to configure behavior:
prompt
(message displayed when asking for first string),
confirm-prompt
(message displayed when asking for the same string again),
not-match-msg
(message displayed when strings do not match),
empty-msg
(message displayed when the entered string is empty),
retries
(number of retries before quitting the loop; when set to nil
or not
given, it will continue indefinitely),
confirmation?
(requires string to be re-entered for confirmation, defaults to true
),
allow-empty?
(allows the entered string to be empty; defaults to false
),
empty-nil?
(returns nil
instead of an empty string; defaults to false
),
empty-quits?
(short-circuits on any empty string and returns nil
; defaults to false
),
empty-quits-nil?
(returns nil
when quitting on empty string; defaults to true
).
Returns the entered string or nil
.
Ask user for a string with optional confirmation using ask-fn to get a string (or nil). Repeats until two entered strings are the same and are not empty. Keyword arguments can be given to configure behavior: `prompt` (message displayed when asking for first string), `confirm-prompt` (message displayed when asking for the same string again), `not-match-msg` (message displayed when strings do not match), `empty-msg` (message displayed when the entered string is empty), `retries` (number of retries before quitting the loop; when set to `nil` or not given, it will continue indefinitely), `confirmation?` (requires string to be re-entered for confirmation, defaults to `true`), `allow-empty?` (allows the entered string to be empty; defaults to `false`), `empty-nil?` (returns `nil` instead of an empty string; defaults to `false`), `empty-quits?` (short-circuits on any empty string and returns `nil`; defaults to `false`), `empty-quits-nil?` (returns `nil` when quitting on empty string; defaults to `true`). Returns the entered string or `nil`.
(bytes-to-string b)
Converts bytes into a string
Converts bytes into a string
(char-ranges->set & ranges)
Returns a set of characters defined as a collection of collections with start and stop character, e.g.: [\A \Z][\0 \9]
Returns a set of characters defined as a collection of collections with start and stop character, e.g.: [\A \Z][\0 \9]
(contains-some? s1 s2)
Takes two indexed collections and returns true if at least one element is shared in both. Otherwise it returns false.
Takes two indexed collections and returns true if at least one element is shared in both. Otherwise it returns false.
(find-first f coll)
(find-first f coll not-found)
Returns the first item from coll for which (f item) returns true or nil if no such item is present. If the given not-found value is supplied, it will return it instead of nil.
Returns the first item from coll for which (f item) returns true or nil if no such item is present. If the given not-found value is supplied, it will return it instead of nil.
(gen-digits num)
(gen-digits num rng)
Generates the given number of random digits and converts all into a single string. When the second argument is present it should be an instance of random number generator used to get the digits.
Generates the given number of random digits and converts all into a single string. When the second argument is present it should be an instance of random number generator used to get the digits.
(get-rand-int n)
(get-rand-int n rng)
Like rand-int but optionally uses random number generator.
Like rand-int but optionally uses random number generator.
(inferred-contains? coll k)
Just like the contains? but if the keyword is namespace-qualified it also checks if the collection contains the same keyword as its key but without a namespace.
Just like the contains? but if the keyword is namespace-qualified it also checks if the collection contains the same keyword as its key but without a namespace.
(inferred-get coll k)
(inferred-get coll k default)
Just like the get function but if the keyword is namespace-qualified it first attempts to look for the value associated with it. If that fails it uses the variant of the keyword without any namespace.
Just like the get function but if the keyword is namespace-qualified it first attempts to look for the value associated with it. If that fails it uses the variant of the keyword without any namespace.
(lazy-iterator-seq coll)
(lazy-iterator-seq coll iter)
Returns a lazy sequence as an interface to the given iterable Java object.
Returns a lazy sequence as an interface to the given iterable Java object.
(mapply f & args)
Like apply but works on named arguments. Takes function f and a list of arguments to be passed, were the last argument should be a map that will be decomposed and passed as named arguments.
Returns the result of calling f.
Like apply but works on named arguments. Takes function f and a list of arguments to be passed, were the last argument should be a map that will be decomposed and passed as named arguments. Returns the result of calling f.
(normalize-name some-name)
(normalize-name some-name default-name)
Takes a name expressed as a string or an identifier. If the object is an identifier (a symbol or a keyword) then it converts it to a string using name function. If the second argument is present then it uses it when the given name or a name derived from identifier is empty.
Takes a name expressed as a string or an identifier. If the object is an identifier (a symbol or a keyword) then it converts it to a string using name function. If the second argument is present then it uses it when the given name or a name derived from identifier is empty.
(normalize-name-with-ns some-name)
(normalize-name-with-ns some-name default-name)
Takes a name expressed as a string or an identifier. If the object is an identifier (a symbol or a keyword) then it converts it to a string using namespace and name functions. If the second argument is present then it uses it when the given name or a name derived from identifier is empty.
Takes a name expressed as a string or an identifier. If the object is an identifier (a symbol or a keyword) then it converts it to a string using namespace and name functions. If the second argument is present then it uses it when the given name or a name derived from identifier is empty.
(ns-infer ns-name k)
(ns-infer ns-name k use-infer)
Takes a string of namespace name and a keyword. If the given keyword is not namespace-qualified it returns a new keyword with the given namespace added. If the given keyword is already equipped with a namespace it returns it.
Takes a string of namespace name and a keyword. If the given keyword is not namespace-qualified it returns a new keyword with the given namespace added. If the given keyword is already equipped with a namespace it returns it.
(random-digits-len x iteration shrink-now)
(random-digits-len x iteration shrink-now rng)
For 0 or 1 it returns its argument. For other positive numbers it returns a random natural number from 1 to this number (inclusive) in 50% cases. In other 50% cases it returns its argument.
For 0 or 1 it returns its argument. For other positive numbers it returns a random natural number from 1 to this number (inclusive) in 50% cases. In other 50% cases it returns its argument.
(read-line-with-prompt)
(read-line-with-prompt prompt)
Reads a line of text from console with optional prompt. Returns a string or nil
when the entered string is empty.
Reads a line of text from console with optional prompt. Returns a string or `nil` when the entered string is empty.
(try-null & body)
Evaluates body and if NullPointerException exception is caught it returns nil. Otherwise it returns the value of last expression in the body.
Evaluates body and if NullPointerException exception is caught it returns nil. Otherwise it returns the value of last expression in the body.
(when-not-empty val & body)
Evaluates body when the given value is a non-empty collection.
Evaluates body when the given value is a non-empty collection.
(with-not-empty obj)
Returns the collection if it's not empty. Otherwise returns nil
.
Returns the collection if it's not empty. Otherwise returns `nil`.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close