lux.functional a LUX module

LUX’s functional programming module. Some functional programming tools lay around here.

Functions

bindFirst (f, arg)

Binds a function’s first parameter to the given argument.

Parameters:

  • function f

    function being bound.

  • any arg

    The bound argument.

Returns:

    function

    A function that, upon being called, does the same as f, but requires only the arguments beyond the first one.

bindLeft (f, arg1[, ...])

Binds a function to the given (left-most) arguments. The arguments must be passed in the apropriate order, according to the function’s specification.

Parameters:

  • function f

    The function being binded.

  • any arg1

    The first bound argument.

  • any ... (optional)

    The remaining bound arguments, in order.

Returns:

    function

    A function that, upon being called, does the same as f, but requires only the remaining right-most arguments that were not binded with it.

curry (f[, n=1])

Creates a n-curried function based on f.

Parameters:

  • function f

    The function being curried.

  • integer n (default: 1)

    How much the function should be curried.

Returns:

    function

    An n-curried version of f.

Usage:

     local result = std.curry(print,2)
     result (arg1) (arg2) (arg3, arg4, ...)

reverse (...)

Reverses the order of the arguments.

Parameters:

  • any ...

    Arbitrary arguments.

Returns:

    any

    The arguments in reversed order.

map (f, a, ...)

Map function. Might overflow the stack and is not tail recursive.

Parameters:

  • function f

    An unary function

  • any a

    First mapped element

  • any ...

    Other to-be-mapped elements

Returns:

    any

    All the results of applying f to the given elements one by one.

expand (n, value, ...)

Expand a value into a value list: value, value, …

Parameters:

  • integer n

    The number of times to expand.

  • any value

    The expanded value

  • any ...

    For internal use inly.

Returns:

    any

    A list of copies of value.