Module fns

Module 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§

All
Function that checks whether all of array items satisfy the provided predicate.
Any
Function that checks whether any of array items satisfy the provided predicate.
Array
Function generating an array by mapping its indexes.
Assert
Assertion function.
AssertClose
Assertion that two values are close to each other.
AssertEq
Equality assertion function.
AssertFails
Assertion that the provided function raises an error. Errors can optionally be matched against a predicate.
Dbgstd
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.
Defer
Allows to define a value recursively, by referencing a value being created.
Filter
Filter function that evaluates the provided function on each item of the tuple and retains only elements for which the function returned true.
FnWrapper
Wrapper of a function containing information about its arguments.
Fold
Reduce (aka fold) function that reduces the provided tuple to a single value.
FromValueError
Error raised when a value cannot be converted to the expected type when using FnWrapper.
If
if function that eagerly evaluates “if” / “else” terms.
Len
Function returning array / object length.
Map
Map function that evaluates the provided function on each item of the tuple.
Merge
Function that merges two tuples.
Push
Function that appends a value onto a tuple.
While
Loop function that evaluates the provided closure while a certain condition is true. Returns the loop state afterwards.

Enums§

Compare
Comparator functions on two primitive arguments. All functions use Arithmetic to determine ordering between the args.
ErrorOutput
Generic error output encompassing all error types supported by wrapped functions.
FromValueErrorKind
Error kinds for FromValueError.
FromValueErrorLocation
Element of the FromValueError location.

Traits§

IntoEvalResult
Converts type into Value or an error. This is used to convert the return type of wrapped functions to the result expected by NativeFn.
TryFromValue
Fallible conversion from Value to a function argument.

Functions§

wrap
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§

Binary
Binary function wrapper.
Quaternary
Quaternary function wrapper.
Ternary
Ternary function wrapper.
Unary
Unary function wrapper.