io.randomseed.utils

added in 1.0.0

Random support functions and macros.

add-spc-b

(add-spc-b s)

Adds space characters to the beginning and end of the given string s if it is not an empty string. Otherwise it returns a string with a single space.

add-spc-l

(add-spc-l s)

Prepends space character to the given string s if it is not an empty string.

add-spc-r

(add-spc-r s)

Appends space character to the given string s if it is not an empty string or a single space.

ask

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

atom?

(atom? v)

b64-to-bytes

(b64-to-bytes s)

Converts Base64 encoded string to array of bytes.

bytes-concat

(bytes-concat)(bytes-concat bary)(bytes-concat bary & byte-arys)

Concatenates byte arrays.

bytes-to-string

(bytes-to-string b)

Converts bytes into a string

bzero

Returns zeroed array of bytes.

char-ranges->set

added in 1.0.0

(char-ranges->set & ranges)

Returns a set of characters defined as a collection of collections with start and stop character, e.g.: \A \Z

const-form?

(const-form? x)

Returns true when x is nil or is of one of the following types: string or keyword or boolean or number or character. Otherwise returns false.

contains-some?

(contains-some? s1 s2)

Takes two indexed collections and returns true if at least one element is shared in both. Otherwise it returns false.

count-digits

added in 1.0.0

(count-digits n)

Returns a number of digits in a decimal number n.

current-thread

(current-thread)

current-thread-id

(current-thread-id)

current-thread-name

(current-thread-name)

defdoc!

macro

(defdoc! v docstr)

empty-ident?

(empty-ident? v)

Returns true if v is an empty identifier.

empty-string?

(empty-string? s)

Returns true if s is an empty string. Will throw an exception when s is not a string.

ensure-ident-keyword

(ensure-ident-keyword id)

ensure-keyword

(ensure-keyword id)

Takes an identifier id and tries to convert it to a keyword. If it is not an identifier, it calls keyword.

ensure-keyword-having-ns

(ensure-keyword-having-ns id ns)

ensure-namespaced-keyword

(ensure-namespaced-keyword id ns)

ensure-ns

(ensure-ns id ns)

Takes an identifier id and a namespace ns (a string), and tries to set a namespace in the identifier. If a namespace already exists in identifier, it is not changed.

ensure-str

(ensure-str v)(ensure-str v & more)

exception?

(exception? v)

find-first

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

fn-name

(fn-name f)

Tries to obtain symbolic function name for the given function f. Uses metadata and Java reflection as fallback.

gen-digits

added in 1.0.0

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

get-rand-int

added in 1.0.0

(get-rand-int n)(get-rand-int n rng)

Like rand-int but optionally uses random number generator.

inferred-contains?

added in 1.0.0

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

inferred-get

added in 1.0.0

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

insert-at

(insert-at index coll element)

Takes an index number index, a collection coll and an element element, and inserts element’s value under the given index number. Uses sequential operations: split-at, concat and cons.

instant?

(instant? v)

is

macro

(is pred val & body)

Takes a predicate pred, a value val and a body. Evaluates val and passes to pred. If the result is truthy it evaluates all expressions from body in an implicit do. Otherwise it returns the value.

is-not

macro

(is-not pred val & body)

Takes a predicate pred, a value val and a body. Evaluates val and passes to pred. If the result is truthy it returns the value. Otherwise it evaluates all expressions from body in an implicit do.

juxt-seq

(juxt-seq & functions)

Like clojure.core/juxt but produces lazy sequence of results instead of a vector.

lazy-iterator-seq

added in 1.0.0

(lazy-iterator-seq coll)(lazy-iterator-seq coll iter)

Returns a lazy sequence as an interface to the given iterable Java object.

mapply

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

must-have-ns

(must-have-ns id ns)

named-to-str

(named-to-str v)

Converts a value v to a string. If keyword is given, it will have : character removed.

named-to-str-trim

(named-to-str-trim v)

Converts a value v to a string and trims its both sides. If keyword is given, it will have : character removed.

nil-or-empty-str?

(nil-or-empty-str? x)

Returns true if the given x is nil or an empty string.

nil-spc-or-empty-str

(nil-spc-or-empty-str s)

Takes a string or nil object s and returns an empty string if it is nil, empty string or a string containing a single space only.

nil-spc-or-empty-str?

(nil-spc-or-empty-str? s)

Returns true if the given value s is nil, an empty string or a string containing a single space only.

normalize-name

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

normalize-name-with-ns

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

normalize-to-bytes

(normalize-to-bytes t)

not-empty-ident?

(not-empty-ident? v)

Returns true if v is not an empty identifier.

not-empty-string?

(not-empty-string? s)

Returns true if s is not an empty string. Will throw an exception when s is not a string.

not-valuable

macro

(not-valuable & more)

not-valuable?

(not-valuable? x)

Returns true if x not valuable: is nil or empty.

ns-infer

added in 1.0.0

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

or-some

macro

(or-some)(or-some x)(or-some x & next)

Same as or but returns first value which is strictly not nil.

parse-long

(parse-long s)(parse-long s default)

parse-num

(parse-num n default)(parse-num n)

parse-percent

(parse-percent n default)(parse-percent n)

parse-re

(parse-re v)

parse-url

(parse-url u)

Parses URL into a map.

percent

pos-val

(pos-val x)

Returns the given value x if it is a positive number. Otherwise it returns nil.

qsome

macro

(qsome pred coll)

Same as clojure.core/some but when coll is a constant form then a source code with or expression is generated instead of some with recurrent predicate application. Short-circuits when pred is nil or false, returning nil.

qstrb

macro

(qstrb)(qstrb a)(qstrb a & more)

Calls strb but checks if the first and only argument is a string, and if it so, returns its literal form without calling strb.

random-digits-len

added in 1.0.0

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

random-uuid

(random-uuid)

read-line-with-prompt

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

replace-first

(replace-first s c r)

Replaces the first appearance of a character c in the given string s with a character r.

safe-parse-long

(safe-parse-long v default)(safe-parse-long v)

safe-parse-num

(safe-parse-num v default)(safe-parse-num v)

safe-parse-percent

(safe-parse-percent v default)(safe-parse-percent v)

sanitize-base-url

(sanitize-base-url url)

simple-keyword-up

(simple-keyword-up v)

simple-quote-form?

(simple-quote-form? x)

Returns true when x is a list or is an instance of clojure.lang.Cons, has 2 elements or less and its first element is the quote symbol, plus its second element is a symbol or const-form? returns true for it.

simple-symbol-up

(simple-symbol-up v)

some-fn*

(some-fn* p)(some-fn* p1 p2)(some-fn* p1 p2 p3)(some-fn* p1 p2 p3 p4)(some-fn* p1 p2 p3 p4 & preds)

Same as clojure.core/some-fn but multiple arguments are passed to each predicate function and nullary variant is not returning nil but calls each predicate without passing any arguments.

Takes a set of predicates and returns a function that returns the first truthy value (not nil and not false) returned by one of its composing predicates against all of its arguments, else it returns a value returned by the last predicate given (which may be false or nil).

some-keyword

(some-keyword v)

some-keyword-simple

(some-keyword-simple v)

some-keyword-up

(some-keyword-up v)

some-long

(some-long s default)(some-long s)

some-str

(some-str v)

Converts the given value v to a string. Keywords are transformed to strings without the : prefix. Empty string or nil will result in nil being returned.

some-str-down

(some-str-down v)

Converts the given value v to a lowercase string. Keywords are transformed to strings without the : prefix. Empty string or nil will result in nil being returned.

some-str-simple

(some-str-simple v)

Converts the given value v to a string. If v is an identifier only its name part is used and namespace is ignored. Keywords are transformed to strings without the : prefix. Empty string or nil will result in nil being returned.

some-str-simple-down

(some-str-simple-down v)

Converts the given value v to a lowercase string. If v is an identifier only its name part is used and namespace is ignored. Keywords are transformed to strings without the : prefix. Empty string or nil will result in nil being returned.

some-str-simple-up

(some-str-simple-up v)

Converts the given value v to an uppercase string. If v is an identifier only its name part is used and namespace is ignored. Keywords are transformed to strings without the : prefix. Empty string or nil will result in nil being returned.

some-str-spc

(some-str-spc s & more)

Takes one or more strings or other objects convertable to strings and concatenates them with spaces. Keywords are transformed to strings without the : prefix.

some-str-squeeze-spc

(some-str-squeeze-spc s & more)

Takes one or more strings or other objects convertable to strings and concatenates them with spaces and squeezes spaces in a resulting string which is returned. Keywords are transformed to strings without the : prefix.

some-str-up

(some-str-up v)

Converts the given value v to an uppercase string. Keywords are transformed to strings without the : prefix. Empty string or nil will result in nil being returned.

some-string

(some-string s)

Takes a string s and returns it unless its value is nil or it is an empty string. A bit more performant but will throw an exception when s is not a string nor nil.

some-symbol

(some-symbol v)

some-symbol-simple

(some-symbol-simple v)

some-symbol-up

(some-symbol-up v)

str-spc

(str-spc s & more)

Takes one or more strings or other objects convertable to strings and concatenates them with spaces.

str-squeeze-spc

(str-squeeze-spc s & more)

Takes one or more strings or other objects convertable to strings and concatenates them with spaces and squeezes spaces in a resulting string which is returned.

strb

(strb a)(strb a b)(strb a b c)(strb a b c d)(strb a b c d e)(strb a b c d e & more)

Like clojure.core/str but faster. Be aware that all arguments except first must be of type String or nil.

strs

macro

(strs)(strs a)(strs a & more)

Converts all arguments to strings and concatenates them with keywords being converted to strings without the : prefix. Neighbouring literal strings and known constant forms will be concatenated at compile time.

strs-simple

macro

(strs-simple)(strs-simple a)(strs-simple a & more)

Converts all arguments to strings and concatenates them. Neighbouring literal strings and known constant forms will be concatenated at compile time.

strspc

macro

(strspc)(strspc a)(strspc a & more)

Converts all arguments to strings and concatenates them with keywords being converted to strings without the : prefix. Neighbouring literal strings and known constant forms will be trimmed on both ends and concatenated at compile time with space characters.

For consecutive non-constant forms (like symbols) simple wrappers will be generated to ensure they are properly trimmed and separated with spaces depending on their values (only single space and empty string are detected).

strspc-squeezed

macro

(strspc-squeezed)(strspc-squeezed a)(strspc-squeezed a & more)

Converts all arguments to strings and concatenates them with keywords being converted to strings without the : prefix. Neighbouring literal strings and known constant forms will be trimmed on both ends and concatenated at compile time with space characters.

For consecutive non-constant forms (like symbols) simple wrappers will be generated to ensure they are properly trimmed and separated with spaces depending on their values (only single space and empty string are detected).

Moreover, spaces will be squeezed for detected constant forms at compile time. No squeezing will be performed at run-time.

text-to-bytes

(text-to-bytes t)

throwable?

(throwable? v)

to-bytes

(to-bytes obj)

Converts object to bytes by converting it to a string first with UTF-8 encoding.

to-lisp-simple-str

(to-lisp-simple-str v)

abc/ip_address –> ip-address

to-lisp-slashed-str

(to-lisp-slashed-str v)

ip_address_is –> ip/address-is

to-lisp-str

(to-lisp-str v)

ip_address –> ip-address

to-lisp-str-replace-first

(to-lisp-str-replace-first v c r)

ipCaddress_to –> ipRaddress-to

to-long

(to-long s default)

to-snake-simple-str

(to-snake-simple-str v)

abc/ip-address –> ip_address

to-snake-slashed-str

(to-snake-slashed-str v)

ip-address-is –> ip/address_is

to-snake-str

(to-snake-str v)

ip-address –> ip_address

to-snake-str-replace-first

(to-snake-str-replace-first v c r)

ipCaddress-to –> ipRaddress_to

to-uuid

(to-uuid)(to-uuid s)

Converts the given value to UUID. If it’s empty or nil, returns nil.

try-null

macro

added in 1.0.0

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

try-require

(try-require n)

Tries to require namespace n and returns the given argument. If the file does not exists, returns nil.

uuid

valuable

macro

(valuable & more)

valuable?

(valuable? x)

Returns true if x valuable: is not nil nor empty.

when-not-empty

macro

added in 1.0.0

(when-not-empty val & body)

Evaluates body when the given value is a non-empty collection.

when-not-valuable

macro

(when-not-valuable v & more)

Evaluates expressions from more in an implicit do when v is nil or empty.

when-valuable

macro

(when-valuable v & more)

Evaluates expressions from more in an implicit do when v is not nil nor empty.

with-not-empty

added in 1.0.0

(with-not-empty obj)

Returns the collection if it’s not empty. Otherwise returns nil.