Module Photon.Functional
Functional Programming / Currying Library.
Info:
- Copyright: Photon Team
- Release: v74 Hot Sulphur Springs
- Author: Joshua Piper
Functions
Photon.Functional.partial(func, ...) | Builds a partial function, with stored arguments. |
Photon.Functional.flip(func) | Returns a function where the first two inputs are flipped. |
Photon.Functional.reverse(vararg) | Reverses a set of input arguments. |
Photon.Functional.compose(...) | Build a function o from f/g so that f(g(x)) == o(x) |
Functions
Methods- Photon.Functional.partial(func, ...)
-
Builds a partial function, with stored arguments.
Parameters:
- func function Input function to curry.
- ... Arguments to store.
Usage:
local positiveOnly = partial(max, 0)
print(positiveOnly(-1)) -- Returns 0.
print(positiveOnly(2)) -- Returns 2.
- Photon.Functional.flip(func)
-
Returns a function where the first two inputs are flipped.
Parameters:
- func function Input function.
Returns:
-
function
Flipped function.
Usage:
local flippedPrint = flip(print)
flippedPrint("hello", "world") -- Outputs: "world hello"
- Photon.Functional.reverse(vararg)
-
Reverses a set of input arguments.
Parameters:
- vararg ... Input argument.
Returns:
-
vararg
Flipped outputs.
See also:
- Photon.Functional.compose(...)
-
Build a function o from f/g so that f(g(x)) == o(x)
Parameters:
- ... vararg Input functions.
Returns:
-
function
Composed function.