#cp.fn
A collection of functions that are useful for working with functions. Heavily inspired by Point-Free's Overture library for Swift.
In general, the functions in this module come in two categories:
- Functions which perform an action directly.
- Functions which return a new function.
The second category of functions are called "combinators". A combinator is a function that returns a new function, often with configuration parameters passed in.
#Submodules
#API Overview
Functions - API calls offered directly by the extension
- all
- any
- call
- chain
- compare
- compose
- constant
- curry
- debug
- flip
- fork
- identity
- ifilter
- none
- over
- pipe
- prefix
- reduce
- resolve
- set
- uncurry
- with
#API Documentation
#Functions
Signature | cp.fn.all(...) -> function |
Type | Function |
Description | A combinator that returns a function that passes its arguments to all the functions in fns and returns the last result, if all functions return a truthy value. Otherwise, it returns nil . |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//fn.lua line 52 |
Signature | cp.fn.any(...) -> function |
Type | Function |
Description | A combinator that returns a function that passes its arguments to all the functions in fns and returns the first truthy result, or nil if all functions return a falsy value. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//fn.lua line 82 |
Signature | cp.fn.call(fn) -> ... |
Type | Function |
Description | Calls the function fn with no arguments, returning the result. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//fn.lua line 169 |
Signature | cp.fn.chain(...) -> function |
Type | Function |
Description | Chain a series of functions together, passing the results of each function on to the next one, returning the last result, or returning nil immediately after all results of a function are nil . |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | src/extensions/cp//fn.lua line 634 |
Signature | cp.fn.compare(...) -> function |
Type | Function |
Description | A combinator that returns a function that checks each provided comparator in turn, returning true if the given comparator returns true , otherwise if the values are equal, checks the next comparator, and so on. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | src/extensions/cp//fn.lua line 182 |
Signature | cp.fn.compose(...) -> function | |
Type | Function | |
Description | A combinator that performs backwards composition of functions, returning a function that is the composition of a list of functions processed from last to first. | |
Parameters |
| ... - A table or a list of functions. |
Returns |
| |
Notes | None | |
Examples | None | |
Source | src/extensions/cp//fn.lua line 221 |
Signature | cp.fn.constant(value) -> function |
Type | Function |
Description | A combinator that returns a function that always returns the value . |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//fn.lua line 241 |
Signature | cp.fn.curry(function, argCount) -> function |
Type | Function |
Description | Curries a function with the specified number of arguments, returning a function that accepts the first argument. It will return other functions that accept the second argument, and so on, until the final argument is collected, and the values are passed to the original function. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//fn.lua line 280 |
Signature | cp.fn.debug(message, ...) -> function |
Type | Function |
Description | Returns a function that will print the provided message to the console. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | src/extensions/cp//fn.lua line 654 |
Signature | cp.fn.flip(fn) -> function |
Type | Function |
Description | A combinator that flips the order of the next two arguments to a curried function. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | src/extensions/cp//fn.lua line 296 |
Signature | cp.fn.fork(...) -> function |
Type | Function |
Description | A combinator that returns a function that returns the result of calling ... with the functions passed in. This can be used to split an input into multiple outputs. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//fn.lua line 140 |
Signature | cp.fn.identity(...) -> ... |
Type | Function |
Description | Returns the values passed in. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//fn.lua line 318 |
Signature | cp.fn.ifilter([predicate]) -> function(table) -> table |
Type | Function |
Description | Returns a function that filters a table using the given predicate, in index order. If the predicate is not provided, the original table will be returned unchanged. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp/fn/table.lua line 173 |
Signature | cp.fn.none(...) -> function |
Type | Function |
Description | A combinator that returns a function that passes its arguments to all the functions in fns and returns true if the first return value from each is falsey , otherwise it returns false . |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//fn.lua line 113 |
Signature | cp.fn.over(setter, fn) -> function |
Type | Function |
Description | A combinator that returns a function that applies the transform function to the setter . |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//fn.lua line 331 |
Signature | cp.fn.pipe(...) -> function | |
Type | Function | |
Description | A combinator that pipes a series of functions together, passing the results of each function on to the next one. The returned function takes any number of inputs and may return any number of inputs, depending on the results of the final function. | |
Parameters |
| ... - A table or list of functions. |
Returns |
| |
Notes |
| |
Examples | None | |
Source | src/extensions/cp//fn.lua line 345 |
Signature | cp.fn.prefix(fn, ...) -> function |
Type | Function |
Description | Prefixes the provided values as the first arguments to the function. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//fn.lua line 370 |
Signature | cp.fn.reduce(fn, initial, ...) -> any |
Type | Function |
Description | Reduces a list of values into a single value. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//fn.lua line 396 |
Signature | cp.fn.resolve(value, ...) -> any |
Type | Function |
Description | If the value is a function, calls it with the provided arguments, otherwise returns the value. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//fn.lua line 416 |
Signature | cp.fn.set(setter, value) -> function |
Type | Function |
Description | Applies a value to an immutable setter function. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//fn.lua line 433 |
Signature | cp.fn.uncurry(fn, argCount) -> function |
Type | Function |
Description | Uncurry a curried function with the specified number of arguments, returning a function the specified number of arguments. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//fn.lua line 465 |
Signature | cp.fn.with(value, fn) -> function |
Type | Function |
Description | A combinator that returns a function that will call the provided function with the provided value as the first argument. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//fn.lua line 481 |