# 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
  • 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.
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
  • table - The table to copy.
Returns
  • A copy of the table.
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
  • 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.
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
  • table - The table to get the first value from.
Returns
  • The first value in the table. May be nil.
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
  • 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.
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
  • 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.
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
  • key - The key to get the value for.
Returns
  • A function that takes a table and returns the value at the specified key.
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
  • 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.
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
  • 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.
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
  • 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.
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
  • 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.
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
  • 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.
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
  • 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.
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
  • 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.
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
  • table - The table to check.
Returns
  • true if the table is empty, otherwise false.
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
  • table - The table to check.
Returns
  • true if the table is not empty, otherwise false.
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
  • table - The table to get the last value from.
Returns
  • The last value in the table. May be nil.
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
  • fn - The function to map.
  • t - The table arguments to map over.
Returns
  • A table with the values updated via the function.
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
  • ... - 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.
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
  • 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})
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
  • key - The key to set.
  • value - The value to set.
Returns
  • A function.
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
  • t - The table to get the size of.
Returns
  • The size of the table.
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
  • ... - 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})
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
  • 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
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
  • 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.
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
  • lists - A table or list of lists.
Returns
  • A list of lists.
Notes None
Examples None
Source src/extensions/cp/fn/table.lua line 444