Module arithmetic_eval::fns

source ·
Expand description

Standard functions for the interpreter, and the tools to define new native functions.

§Defining native functions

There are several ways to define new native functions:

  • Implement NativeFn manually. This is the most versatile approach, but it can be overly verbose.
  • Use FnWrapper or the wrap function. This allows specifying arguments / output with custom types (such as bool or a Number).

Structs§

  • Function that checks whether all of array items satisfy the provided predicate.
  • Function that checks whether any of array items satisfy the provided predicate.
  • Function generating an array by mapping its indexes.
  • Assertion function.
  • Assertion that two values are close to each other.
  • Equality assertion function.
  • Assertion that the provided function raises an error. Errors can optionally be matched against a predicate.
  • Acts similarly to the dbg! macro, outputting the argument(s) to stderr and returning them. If a single argument is provided, it’s returned as-is; otherwise, the arguments are wrapped into a tuple.
  • Allows to define a value recursively, by referencing a value being created.
  • Filter function that evaluates the provided function on each item of the tuple and retains only elements for which the function returned true.
  • Wrapper of a function containing information about its arguments.
  • Reduce (aka fold) function that reduces the provided tuple to a single value.
  • Error raised when a value cannot be converted to the expected type when using FnWrapper.
  • if function that eagerly evaluates “if” / “else” terms.
  • Function returning array / object length.
  • Map function that evaluates the provided function on each item of the tuple.
  • Function that merges two tuples.
  • Function that appends a value onto a tuple.
  • Loop function that evaluates the provided closure while a certain condition is true. Returns the loop state afterwards.

Enums§

Traits§

Functions§

  • Wraps a function enriching it with the information about its arguments. This is a slightly shorter way to create wrappers compared to calling FnWrapper::new().

Type Aliases§