cp.fn.table
Table-related functions.
API Overview
Constants - Useful values which cannot be changed
this
Functions - API calls offered directly by the extension
call copy filter first firstMatching flatten get hasAtLeast hasAtMost hasExactly hasLessThan hasMoreThan hasValue imap isEmpty isNotEmpty last map matchesExactItems mutate set size sort split zip zipAll
API Documentation
Constants
this
| Signature | cp.fn.table.this -> table |
| Type | Constant |
| Description | A table which can have any named property key, which will be a function combinator that expects to receive a table and returns the value at the specified key. These are essentially equivalent statements: cp.fn.table.this.key and cp.fn.table.get "key". |
| Notes | None |
| Source | src/extensions/cp/fn/table.lua line 164 |
Functions
call
| Signature | cp.fn.table.call(name, ...) -> function(table) -> ... |
| Type | Function |
| Description | Calls a function on a table with the specified name. Any additional arguments are passed to the function. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 23 |
copy
| Signature | cp.fn.table.copy(table) -> table |
| Type | Function |
| Description | Performs a shallow copy of the specified table using pairs. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 46 |
filter
| Signature | cp.fn.table.filter([predicate]) -> function(table) -> table |
| Type | Function |
| Description | Returns a function that filters a table using the given predicate. 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 63 |
first
| Signature | cp.fn.table.first(table) -> any | nil |
| Type | Function |
| Description | Returns the first value in the table. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 85 |
firstMatching
| Signature | cp.fn.table.firstMatching(predicate) -> function(table) -> any | nil |
| Type | Function |
| Description | Returns a function that will return the first value in the table that matches the predicate. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 98 |
flatten
| Signature | cp.fn.table.flatten(t) -> table |
| Type | Function |
| Description | Flattens a table. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 117 |
get
| Signature | cp.fn.table.get(key) -> function(table) -> any |
| Type | Function |
| Description | Returns a function that returns the value at the specified key in a table. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 149 |
hasAtLeast
| Signature | cp.fn.table.hasAtLeast(count) -> function(table) -> boolean |
| Type | Function |
| Description | Returns a function that checks if the table has at least the given number of items. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 502 |
hasAtMost
| Signature | cp.fn.table.hasAtMost(count) -> function(table) -> boolean |
| Type | Function |
| Description | Returns a function that checks if the table has at most the given number of items. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 517 |
hasExactly
| Signature | cp.fn.table.hasExactly(count) -> function(table) -> boolean |
| Type | Function |
| Description | Returns a function that checks if the table has exactly the given number of items. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 532 |
hasLessThan
| Signature | cp.fn.table.hasLessThan(count) -> function(table) -> boolean |
| Type | Function |
| Description | Returns a function that checks if the table has less than the given number of items. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 562 |
hasMoreThan
| Signature | cp.fn.table.hasMoreThan(count) -> function(table) -> boolean |
| Type | Function |
| Description | Returns a function that checks if the table has more than the given number of items. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 547 |
hasValue
| Signature | cp.fn.table.hasValue(key[, predicate]) -> function(table) -> boolean |
| Type | Function |
| Description | Returns a function that checks if the table has a value at the specified key. If a predicate is provided, the value is checked using the predicate. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 577 |
imap
| Signature | cp.fn.table.imap(fn, values) -> table of any | ... |
| Type | Function |
| Description | Maps a function over a table using ipairs. The function is passed the current value and the key. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 195 |
isEmpty
| Signature | cp.fn.table.isEmpty(table) -> boolean |
| Type | Function |
| Description | Returns true if the table is empty. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 476 |
isNotEmpty
| Signature | cp.fn.table.isNotEmpty(table) -> boolean |
| Type | Function |
| Description | Returns true if the table is not empty. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 489 |
last
| Signature | cp.fn.table.last(table) -> any | nil |
| Type | Function |
| Description | Returns the last value in the table. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 220 |
map
| Signature | cp.fn.table.map(fn, t) -> table of any |
| Type | Function |
| Description | Maps a function over a table using pairs. The function is passed the current value and the key. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 257 |
matchesExactItems
| Signature | cp.fn.table.matchesExactItems(...) -> function(table) -> boolean |
| Type | Function |
| Description | Returns a function that will return true if the table exactly the number of items that match the provided list of predicates. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 233 |
mutate
| Signature | cp.fn.table.mutate(key) -> function(fn) -> function(table) -> table |
| Type | Function |
| Description | Returns a function that accepts an immutible transformer function, which returns another function that accepts a table. When called, it will apply the transformation to the named key in the table. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 275 |
set
| Signature | cp.fn.table.set(key, value) -> function(table) -> table |
| Type | Function |
| Description | Returns a function that accepts a table and sets the value at the specified key. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 297 |
size
| Signature | cp.fn.table.size(t) -> number |
| Type | Function |
| Description | Returns the size of the table. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 314 |
sort
| Signature | cp.fn.table.sort(...) -> function(table) -> table |
| Type | Function |
| Description | A combinator that returns a function that accepts a table and returns a new table, sorted with the compare functions. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 327 |
split
| Signature | cp.fn.table.split(predicate) -> function(table) -> table of tables, table |
| Type | Function |
| Description | Returns a function that accepts a table and splits it into multiple tables whenever it encounters a value that matches the predicate. The final table is a list containing each table that was split, followed by a table containing the splitter values. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 351 |
zip
| Signature | cp.fn.table.zip(lists) -> table | ... |
| Type | Function |
| Description | Zips a series of lists together, returning a list combining the values from the provided lists. The returned list will have the same length as the shortest list. Each sub-list will contain the values from the corresponding list in the argument list. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 413 |
zipAll
| Signature | cp.fn.table.zipAll(lists) -> function |
| Type | Function |
| Description | Zips a series of lists together, returning a list of lists. The returned list will have the same length as the longest list. Each sub-list will contain the values from the corresponding list in the argument list. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | src/extensions/cp/fn/table.lua line 444 |