Rudi ships with a set of built-in functions. When embedding Rudi, this set can be extended or overwritten as desired to inject custom functions. It is not possible to define functions in an Rudi program itself.
As a rule of thumb, functions who name ends with a question mark return a boolean,
like eq?
or has-prefix?
. Functions with an exclamation point at the end are
not stateless but meant to modify their first argument (see the
language spec regarding the bang modifier in tuples). The
question mark is part of the function name itself, but the bang modifier can be
applied to all functions (so technically eq?!
is valid, though weird looking).
Additional functionality is available in the extended library.
case
– chooses the first expression for which the test is truedefault
– returns the default value if the first argument is emptydelete
– removes a key from an object or an item from a vectordo
– eval a sequence of statements where only one expression is validempty?
– returns true when the given value is empty-ish (0, false, null, "", ...)error
– returns an errorhas?
– returns true if the given symbol's path expression points to an existing valueif
– evaluate one of two expressions based on a conditionset
– set a value in a variable/document, only really useful with ! modifier (set!)try
– returns the fallback if the first expression errors out
humanely
– evaluates the child expressions using humane coalescingpedantically
– evaluates the child expressions using pedantic coalescingstrictly
– evaluates the child expressions using strict coalescing
eq?
– equality check: return true if both arguments are the samegt?
– returns a > bgte?
– returns a >= bidentical?
– likeeq?
, but always uses strict coalecsinglike?
– likeeq?
, but always uses humane coalecsinglt?
– returns a < blte?
– returns a <= b
now
– returns the current date & time (UTC), formatted like a Go date
from-base64
– decode a base64 encoded stringfrom-json
– decode a JSON stringto-base64
– apply base64 encoding to the given stringto-json
– encode the given value using JSON
sha1
– return the lowercase hex representation of the SHA-1 hashsha256
– return the lowercase hex representation of the SHA-256 hashsha512
– return the lowercase hex representation of the SHA-512 hash
filter
– returns a copy of a given vector/object with only those elements remaining that satisfy a conditionmap
– applies an expression to every element in a vector or objectrange
– allows to iterate (loop) over a vector or object
and
– returns true if all arguments are truenot
– negates the given argumentor
– returns true if any of the arguments is true
add
– returns the sum of all of its argumentsdiv
– returns arg1 / arg2 / .. / argN (always a floating point division, regardless of arguments)mult
– returns the product of all of its argumentssub
– returns arg1 - arg2 - .. - argN
append
– appends more strings to a string or arbitrary items into a vectorconcat
– concatenates items in a vector using a common glue stringcontains?
– returns true if a string contains a substring or a vector contains the given elementhas-prefix?
– returns true if the given string has the prefixhas-suffix?
– returns true if the given string has the suffixlen
– returns the length of a string, vector or objectprepend
– prepends more strings to a string or arbitrary items into a vectorreplace
– returns a copy of a string with the a substring replaced by anotherreverse
– reverses a string or the elements of a vectorsplit
– splits a string into a vectorto-lower
– returns the lowercased version of the given stringto-upper
– returns the uppercased version of the given stringtrim
– returns the given whitespace with leading/trailing whitespace removedtrim-prefix
– removes the prefix from the string, if it existstrim-suffix
– removes the suffix from the string, if it exists
to-bool
– try to convert the given argument losslessly to a boolto-float
– try to convert the given argument losslessly to a float64to-int
– try to convert the given argument losslessly to an int64to-string
– try to convert the given argument losslessly to a stringtype-of
– returns the type of a given value (e.g. "string" or "number")
func
– defines a new function