#cp.fn.value

A collection of functions for working with values.


#API Overview

Functions - API calls offered directly by the extension


#API Documentation

#Functions

Signaturecp.fn.value.default(...) -> function(...) -> ...
TypeFunction
DescriptionA combinator that takes a list of default values and returns a function that accepts a list of values and returns the same number of values, with either the value passed in or the default value if that value is nil.
Parameters
  • ... - A list of default values.
Returns
  • A function that accepts a list of values and returns the same number of values, with either the value passed in or the default value if that value is nil.
Notes
  • Example: cp.fn.value.default(1, 2, 3)(5, nil, 6) -- returns 5, 2, 6
ExamplesNone
Sourcesrc/extensions/cp/fn/value.lua line 17

Signaturecp.fn.value.filter(predicate, ...) -> function(value) -> value | nil
TypeFunction
DescriptionFilters a value using a list of predicates which must all be true to succeed.
Parameters
  • predicate - A function that takes a value and returns true or false.
  • ... - Optional additional predicates which must all be true to succeed.
Returns
  • A function that takes a value and returns the value if the predicates all return true, otherwise nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/value.lua line 42

Signaturecp.fn.value.is(other) -> function(value) -> boolean
TypeFunction
DescriptionReturns a function that returns true if the value is equal to the other value. If other is a function, then it will be called with no arguments and the result will be compared.
Parameters
  • other - A value or a function that returns a value.
Returns
  • A function that takes a value and returns true if the value is equal to the other value, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/value.lua line 95

Signaturecp.fn.value.map(mapper) -> function(value) -> any | nil
TypeFunction
DescriptionIf the value is not nil, then it will be passed to the mapper function and the result returned.
Parameters
  • mapper - A function that takes a value and returns a value.
Returns
  • A function that takes a value and returns the result of the mapper function, or nil if the value is nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/value.lua line 61

Signaturecp.fn.value.matches(predicate, ...) -> function(value) -> boolean
TypeFunction
DescriptionReturns a function that returns true if the value matches the predicates.
Parameters
  • predicate - A function that takes a value and returns true or false.
  • ... - Optional additional predicates which must all be true to succeed.
Returns
  • A function that takes a value and returns true if the value matches the all predicates, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/fn/value.lua line 78