Skip to content

Latest commit

 

History

History
111 lines (84 loc) · 6.48 KB

README.md

File metadata and controls

111 lines (84 loc) · 6.48 KB

Rudi Standard Library

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.

core

  • case – chooses the first expression for which the test is true
  • default – returns the default value if the first argument is empty
  • delete – removes a key from an object or an item from a vector
  • do – eval a sequence of statements where only one expression is valid
  • empty? – returns true when the given value is empty-ish (0, false, null, "", ...)
  • error – returns an error
  • has? – returns true if the given symbol's path expression points to an existing value
  • if – evaluate one of two expressions based on a condition
  • set – set a value in a variable/document, only really useful with ! modifier (set!)
  • try – returns the fallback if the first expression errors out

coalesce

  • humanely – evaluates the child expressions using humane coalescing
  • pedantically – evaluates the child expressions using pedantic coalescing
  • strictly – evaluates the child expressions using strict coalescing

compare

  • eq? – equality check: return true if both arguments are the same
  • gt? – returns a > b
  • gte? – returns a >= b
  • identical? – like eq?, but always uses strict coalecsing
  • like? – like eq?, but always uses humane coalecsing
  • lt? – returns a < b
  • lte? – returns a <= b

datetime

  • now – returns the current date & time (UTC), formatted like a Go date

encoding

  • from-base64 – decode a base64 encoded string
  • from-json – decode a JSON string
  • to-base64 – apply base64 encoding to the given string
  • to-json – encode the given value using JSON

hashing

  • sha1 – return the lowercase hex representation of the SHA-1 hash
  • sha256 – return the lowercase hex representation of the SHA-256 hash
  • sha512 – return the lowercase hex representation of the SHA-512 hash

lists

  • filter – returns a copy of a given vector/object with only those elements remaining that satisfy a condition
  • map – applies an expression to every element in a vector or object
  • range – allows to iterate (loop) over a vector or object

logic

  • and – returns true if all arguments are true
  • not – negates the given argument
  • or – returns true if any of the arguments is true

math

  • add – returns the sum of all of its arguments
  • div – returns arg1 / arg2 / .. / argN (always a floating point division, regardless of arguments)
  • mult – returns the product of all of its arguments
  • sub – returns arg1 - arg2 - .. - argN

strings

  • append – appends more strings to a string or arbitrary items into a vector
  • concat – concatenates items in a vector using a common glue string
  • contains? – returns true if a string contains a substring or a vector contains the given element
  • has-prefix? – returns true if the given string has the prefix
  • has-suffix? – returns true if the given string has the suffix
  • len – returns the length of a string, vector or object
  • prepend – prepends more strings to a string or arbitrary items into a vector
  • replace – returns a copy of a string with the a substring replaced by another
  • reverse – reverses a string or the elements of a vector
  • split – splits a string into a vector
  • to-lower – returns the lowercased version of the given string
  • to-upper – returns the uppercased version of the given string
  • trim – returns the given whitespace with leading/trailing whitespace removed
  • trim-prefix – removes the prefix from the string, if it exists
  • trim-suffix – removes the suffix from the string, if it exists

types

  • to-bool – try to convert the given argument losslessly to a bool
  • to-float – try to convert the given argument losslessly to a float64
  • to-int – try to convert the given argument losslessly to an int64
  • to-string – try to convert the given argument losslessly to a string
  • type-of – returns the type of a given value (e.g. "string" or "number")

rudifunc

  • func – defines a new function