#cp.fn.table

Table-related functions.


#API Overview

Constants - Useful values which cannot be changed

Functions - API calls offered directly by the extension


#API Documentation

#Constants

Signaturecp.fn.table.this -> table
TypeConstant
DescriptionA 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".
NotesNone
Sourcesrc/extensions/cp/fn/table.lua line 164

#Functions

Signaturecp.fn.table.call(name, ...) -> function(table) -> ...
TypeFunction
DescriptionCalls a function on a table with the specified name. Any additional arguments are passed to the function.
Parameters
  • name - The name of the function to call.
  • ... - Any additional arguments to pass to the function.
Returns
  • The function that will accept a table and call the function with the specified name.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 23

Signaturecp.fn.table.copy(table) -> table
TypeFunction
DescriptionPerforms a shallow copy of the specified table using pairs.
Parameters
  • table - The table to copy.
Returns
  • A copy of the table.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 46

Signaturecp.fn.table.filter([predicate]) -> function(table) -> table
TypeFunction
DescriptionReturns a function that filters a table using the given predicate. If the predicate is not provided, the original table will be returned unchanged.
Parameters
  • predicate - A function that takes a value and returns true if the value should be included in the filtered table.
Returns
  • A function that takes a table and returns a filtered table.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 63

Signaturecp.fn.table.first(table) -> any | nil
TypeFunction
DescriptionReturns the first value in the table.
Parameters
  • table - The table to get the first value from.
Returns
  • The first value in the table. May be nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 85

Signaturecp.fn.table.firstMatching(predicate) -> function(table) -> any | nil
TypeFunction
DescriptionReturns a function that will return the first value in the table that matches the predicate.
Parameters
  • predicate - A function that will be passed each value in the table. If it returns true, the value will be returned.
Returns
  • A function that will return the first value in the table that matches the predicate. May be nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 98

Signaturecp.fn.table.flatten(t) -> table
TypeFunction
DescriptionFlattens a table.
Parameters
  • t - The table to flatten.
Returns
  • A new table with all values flattened.
Notes
  • This function will not flatten nested tables.
  • If the table has an n field, it will be used as the length, instead of #t.
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 117

Signaturecp.fn.table.get(key) -> function(table) -> any
TypeFunction
DescriptionReturns a function that returns the value at the specified key in a table.
Parameters
  • key - The key to get the value for.
Returns
  • A function that takes a table and returns the value at the specified key.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 149

Signaturecp.fn.table.hasAtLeast(count) -> function(table) -> boolean
TypeFunction
DescriptionReturns a function that checks if the table has at least the given number of items.
Parameters
  • count - The number of items to check for.
Returns
  • A function that takes a table and returns true if the table has at least the given number of items, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 502

Signaturecp.fn.table.hasAtMost(count) -> function(table) -> boolean
TypeFunction
DescriptionReturns a function that checks if the table has at most the given number of items.
Parameters
  • count - The number of items to check for.
Returns
  • A function that takes a table and returns true if the table has at most the given number of items, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 517

Signaturecp.fn.table.hasExactly(count) -> function(table) -> boolean
TypeFunction
DescriptionReturns a function that checks if the table has exactly the given number of items.
Parameters
  • count - The number of items to check for.
Returns
  • A function that takes a table and returns true if the table has exactly the given number of items, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 532

Signaturecp.fn.table.hasLessThan(count) -> function(table) -> boolean
TypeFunction
DescriptionReturns a function that checks if the table has less than the given number of items.
Parameters
  • count - The number of items to check for.
Returns
  • A function that takes a table and returns true if the table has less than the given number of items, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 562

Signaturecp.fn.table.hasMoreThan(count) -> function(table) -> boolean
TypeFunction
DescriptionReturns a function that checks if the table has more than the given number of items.
Parameters
  • count - The number of items to check for.
Returns
  • A function that takes a table and returns true if the table has more than the given number of items, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 547

Signaturecp.fn.table.hasValue(key[, predicate]) -> function(table) -> boolean
TypeFunction
DescriptionReturns 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
  • key - The value to check for.
  • predicate - An optional predicate to use to check the value.
Returns
  • A function that takes a table and returns true if the table has the given value, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 577

Signaturecp.fn.table.imap(fn, values) -> table of any | ...
TypeFunction
DescriptionMaps a function over a table using ipairs. The function is passed the current value and the key.
Parameters
  • fn - The function to map.
  • values - The table or list of arguments to map over.
Returns
  • A table or list of the results of the function.
Notes
  • If the values are a table, the results will be a table. Otherwise, the results will be a vararg list.
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 195

Signaturecp.fn.table.isEmpty(table) -> boolean
TypeFunction
DescriptionReturns true if the table is empty.
Parameters
  • table - The table to check.
Returns
  • true if the table is empty, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 476

Signaturecp.fn.table.isNotEmpty(table) -> boolean
TypeFunction
DescriptionReturns true if the table is not empty.
Parameters
  • table - The table to check.
Returns
  • true if the table is not empty, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 489

Signaturecp.fn.table.last(table) -> any | nil
TypeFunction
DescriptionReturns the last value in the table.
Parameters
  • table - The table to get the last value from.
Returns
  • The last value in the table. May be nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 220

Signaturecp.fn.table.map(fn, t) -> table of any
TypeFunction
DescriptionMaps a function over a table using pairs. The function is passed the current value and the key.
Parameters
  • fn - The function to map.
  • t - The table arguments to map over.
Returns
  • A table with the values updated via the function.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 257

Signaturecp.fn.table.matchesExactItems(...) -> function(table) -> boolean
TypeFunction
DescriptionReturns a function that will return true if the table exactly the number of items that match the provided list of predicates.
Parameters
  • ... - A list of predicates.
Returns
  • A function that will return true if the table exactly the number of items that match the provided list of predicates.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 233

Signaturecp.fn.table.mutate(key) -> function(fn) -> function(table) -> table
TypeFunction
DescriptionReturns 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
  • key - The key to set.
Returns
  • A function.
Notes
  • The returned function will mutate the table passed in, as well as returning it.
  • Example usage: fn.table.mutate("foo")(function(value) return value + 1 end)({value = 1})
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 275

Signaturecp.fn.table.set(key, value) -> function(table) -> table
TypeFunction
DescriptionReturns a function that accepts a table and sets the value at the specified key.
Parameters
  • key - The key to set.
  • value - The value to set.
Returns
  • A function.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 297

Signaturecp.fn.table.size(t) -> number
TypeFunction
DescriptionReturns the size of the table.
Parameters
  • t - The table to get the size of.
Returns
  • The size of the table.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 314

Signaturecp.fn.table.sort(...) -> function(table) -> table
TypeFunction
DescriptionA combinator that returns a function that accepts a table and returns a new table, sorted with the compare functions.
Parameters
  • ... - The list of compare functions to use, in order.
Returns
  • A function.
Notes
  • The compare functions should take two arguments and return true if the first argument is less than the second.
  • The returned result will be a shallow copy of the original in a new table. The original table will not be modified.
  • If no compare functions are provided, the table will be sorted "natural" sorting order (a < b).
  • Example usage: fn.table.sort(function(a, b) return a > b end)({1, 2, 3})
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 327

Signaturecp.fn.table.split(predicate) -> function(table) -> table of tables, table
TypeFunction
DescriptionReturns 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
  • predicate - A function that will be passed each value in the table. If it returns true, the value will be returned.
Returns
  • A function that accepts a table to split and returns a table of tables, followed by a table of splitter values
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 351

Signaturecp.fn.table.zip(lists) -> table | ...
TypeFunction
DescriptionZips 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
  • lists - A table or list of lists.
Returns
  • A function which returns a list combining the values from the provided lists.
Notes
  • If a table is provided, a table is returned. If a vararg is provided, a vararg is returned.
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 413

Signaturecp.fn.table.zipAll(lists) -> function
TypeFunction
DescriptionZips 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
  • lists - A table or list of lists.
Returns
  • A list of lists.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/table.lua line 444