Module moses

Utility-belt library for functional programming in Lua (source)

Info:

Operator functions

operator.add (a, b) Returns a + b.
operator.concat (a, b) Returns concatenation of a and b.
operator.div (a, b) Returns a / b.
operator.eq (a, b) Checks if a equals b.
operator.exp (a, b) Returns a ^ b.
operator.floordiv (a, b) Performs floor division (//) between a and b.
operator.ge (a, b) Returns logical a and b.
operator.ge (a, b) Checks if a is greater or equal to b.
operator.gt (a, b) Checks if a is strictly greater than b.
operator.intdiv (a, b) Performs integer division between a and b.
operator.le (a, b) Checks if a is less or equal to b.
operator.length (a) Returns the length of a.
operator.lnot (a) Returns logical not a.
operator.lor (a, b) Returns logical a or b.
operator.lt (a, b) Checks if a is strictly less than b.
operator.mod (a, b) Returns a % b.
operator.mul (a, b) Returns a * b.
operator.neq (a, b) Checks if a not equals b.
operator.sub (a, b) Returns a - b.
operator.unm (a) Returns -a.

Table functions

adjust (t, key, f) Adjusts the value at a given key using a function or a value.
all (t, f) Checks if all values in a table are passing an iterator test.
allEqual (t[, comp]) Checks if all values in a collection are equal.
at (t, ...) Collects values at given keys and return them wrapped in an array.
best (t, f) Returns the best value passing a selector function.
clear (t) Clears a table.
containsKeys (t, other) Checks if all the keys of other table exists in table t.
count (t[, val]) Counts occurrences of a given value in a table.
countBy (t, iter) Groups values in a collection and counts them.
countf (t, f) Counts the number of values passing a predicate test.
cycle (t[, n]) Loops n times through a table.
detect (t, value) Performs a linear search for a value in a table.
each (t, f) Iterates on key-value pairs, calling f (v, k) at every step.
eachi (t, f) Iterates on integer key-value pairs, calling f(v, k) every step.
findWhere (t, props) Returns the first value having specified keys props.
groupBy (t, iter) Splits a table into subsets groups.
include (t, value) Performs a linear search for a value in a table.
invoke (t, method) Invokes a method on each value in a table.
map (t, f) Maps f (v, k) on value-key pairs, collects and returns the results.
mapReduce (t, f[, state]) Reduces a table while saving intermediate states.
mapReduceRight (t, f[, state]) Reduces a table while saving intermediate states.
max (t[, transform]) Returns the max value in a collection.
min (t[, transform]) Returns the min value in a collection.
pluck (t, key) Extracts values in a table having a given key.
reduce (t, f[, state]) Reduces a table, left-to-right.
reduceBy (t, f, pred[, state[, ...]]) Reduces values in a table passing a given predicate.
reduceRight (t, f[, state]) Reduces a table, right-to-left.
reject (t, f) Clones a table while dropping values passing an iterator test.
same (a, b) Checks if two tables are the same.
sameKeys (tA, tB) Checks if both given tables have the same keys.
select (t, f) Selects and returns values passing an iterator test.
size ([...]) Counts the number of values in a collection.
sort (t[, comp]) Sorts a table, in-place.
sortBy (t[, transform[, comp]]) Sorts a table in-place using a transform.
sortedk (t[, comp]) Iterates on values with respect to key order.
sortedv (t[, comp]) Iterates on values with respect to values order.
where (t, props) Returns all values having specified keys props.

Array functions

addTop (array, ...) Adds all passed-in values at the top of an array.
aperture (array[, n]) Iterator returning sliding partitions of an array.
append (array, other) Clones array and appends values from another array.
chunk (array, f) Chunks together consecutive values.
compact (array) Returns all truthy values (removes falses and nils).
concat (array[, sep[, i[, j]]]) Concatenates values in a given array.
difference (array, another) Returns values from an array not present in all passed-in args.
disjoint (...) Checks if all passed in arrays are disjunct.
dropWhile (array, f) Collects values from a given array.
duplicates (array) Returns an array list of all duplicates in array.
fill (array, value[, i[, j]]) Replaces elements in a given array with a given value.
find (array, value[, from]) Looks for the first occurrence of a given value in an array.
findIndex (array, pred) Returns the first index at which a predicate returns true.
findLastIndex (array, pred) Returns the last index at which a predicate returns true.
first (array[, n]) Returns the first N values in an array.
flatten (array[, shallow]) Flattens a nested array.
indexOf (array, value) Returns the index of the first occurrence of value in an array.
initial (array[, n]) Returns all values in an array excluding the last N values.
interleave (...) Interleaves arrays.
interpose (array, value) Interposes value in-between consecutive pair of values in array.
intersection (...) Returns the intersection of all passed-in arrays.
isunique (array) Checks if a given array contains distinct values.
last (array[, n]) Returns the last N values in an array.
lastIndexOf (array, value) Returns the index of the last occurrence of value in an array.
mean (array) Returns the mean of an array of numbers.
median (array) Returns the median of an array of numbers.
nsorted (array[, n[, comp]]) Returns the n-top values satisfying a predicate.
nth (array, index) Returns the value at a given index.
ones (n) Returns an array of n 1's.
overlapping (array[, n[, pads]]) Iterator returning overlapping partitions of an array.
pack (...) Converts a list of arguments to an array.
pairwise (array) Iterator returning sliding pairs of an array.
partition (array[, n[, pads]]) Iterator returning partitions of an array.
permutation (array) Iterator returning the permutations of an array.
powerset (array) Returns the powerset of array values.
prepend (array, ...) Adds all passed-in values at the top of an array.
product (array) Returns the product of array values.
pull (array, ...) Removes all provided values in a given array.
push (array, ...) Pushes all passed-in values at the end of an array.
range ([from[, to[, step]]]) Produces a flexible list of numbers.
removeRange (array[, start[, finish]]) Removes values at an index within the range [start, finish].
rep (value, n) Creates an array list of n values, repeated.
rest (array[, index]) Returns all values after index.
reverse (array) Returns an array where values are in reverse order.
sample (array[, n[, seed]]) Samples n random values from an array.
sampleProb (array, prob[, seed]) Return elements from a sequence with a given probability.
selectWhile (array, f) Collects values from a given array.
shift (array[, n]) Removes and returns the values at the top of a given array.
shuffle (array[, seed]) Returns a shuffled copy of a given array.
slice (array[, start[, finish]]) Slices values indexed within [start, finish] range.
sortedIndex (array, the[, comp[, sort]]) Returns the index at which a value should be inserted.
sum (array) Returns the sum of array values.
symmetricDifference (array, array2) Performs a symmetric difference.
union (...) Returns the duplicate-free union of all passed in arrays.
unique (array) Produces a duplicate-free version of a given array.
unshift (array[, n]) Removes and returns the values at the end of a given array.
vector (value, n) Returns an array of n times a given value.
xpairs (valua, array) Creates pairs from value and array.
xpairsRight (valua, array) Creates pairs from value and array.
xprod (array, array2) Returns all possible pairs built from given arrays.
zeros (n) Returns an array of n zeros.
zip (...) Merges values of each of the passed-in arrays in subsets.
zipWith (f, ...) Merges values using a given function.

Utility functions

after (f, count) Returns a version of f that runs on the count-th call.
applySpec (specs) Returns a function which applies specs on args.
ary (f[, n]) Returns a function which accepts up to n args.
before (f, count) Returns a version of f that will run no more than count times.
bind (f, v) Binds v to be the first argument to f.
bind2 (f, v) Binds v to be the second argument to f.
bindall (obj, ...) Binds methods to object.
bindn (f, ...) Binds ... to be the N-first arguments to function f.
both (...) Returns a validation function.
call (f[, ...]) Calls f with the supplied arguments.
castArray (value) Casts value as an array if it is not one.
complement (f) Returns the logical complement of a given function.
compose (...) Composes functions.
cond (conds) Returns a function which iterate over a set of conditions.
constant (value) Creates a constant function which returns the same output on every call.
converge (f, g, h) Converges two functions into one.
curry (f[, n_args]) Curries a function.
dispatch (...) Returns a dispatching function.
either (...) Returns a validation function.
flip (f) Creates a function of f with arguments flipped in reverse order.
identity (value) Returns the passed-in value.
iterator (f, value[, n]) Produces an iterator which repeatedly apply a function f onto an input.
iterlen (...) Returns the length of an iterator.
juxtapose (value, ...) Calls a sequence of passed-in functions with the same argument.
memoize (f) Memoizes a given function by caching the computed result.
neither (...) Returns a validation function.
noarg (f) Returns a function with an arity of 0.
noop () The no operation function.
nthArg (n) Returns a function that gets the nth argument.
once (f) Returns a version of f that runs only once.
over (...) Creates a function that runs transforms on all arguments it receives.
overArgs (f, ...) Creates a function that invokes f with its arguments transformed.
overEvery (...) Creates a validation function.
overSome (...) Creates a validation function.
partial (f, ...) Partially apply a function by filling in any number of its arguments.
partialRight (f, ...) Similar to partial, but from the right.
pipe (value, ...) Pipes a value through a series of functions.
rearg (f, indexes) Returns a function which runs with arguments rearranged.
skip (iter[, n]) Consumes the first n values of a iterator then returns it.
tabulate (...) Iterates over an iterator and returns its values in an array.
thread (value, ...) Threads value through a series of functions.
threadRight (value, ...) Threads value through a series of functions.
time (f[, ...]) Returns the execution time of f (...) and its returned values.
times (iter[, n]) Runs iter function n times.
unary (f) Returns a function which accepts up to one arg.
unfold (f, seed) Builds a list from a seed value.
uniqueId ([template]) Generates an unique ID for the current session.
wrap (f, wrapper) Wraps f inside of the wrapper function.

Object functions

chain (value) Returns a wrapped object.
clone (obj[, shallow]) Clones a given object properties.
extend (destObj, ...) Extends an object properties.
flattenPath (obj, ...) Flattens object under property path onto provided object.
functions ([obj]) Returns a sorted list of all methods names found in an object.
has (obj, key) Checks if a given object implements a property.
import ([context[, noConflict]]) Imports all library functions into a context.
invert (obj) Swaps keys with values.
isArray (obj) Checks if the given argument is an array.
isBoolean (obj) Checks if the given argument is a boolean.
isCallable (obj) Checks if the given argument is callable.
isEmpty ([obj]) Checks if the given pbject is empty.
isEqual (objA, objB[, useMt]) Performs a deep comparison test between two objects.
isFinite (obj) Checks if the given argument is a finite number.
isFunction (obj) Checks if the given argument is a function.
isInteger (obj) Checks if the given argument is an integer.
isIterable (obj) Checks if the given object is iterable with pairs (or ipairs).
isNaN (obj) Checks if the given argument is NaN (see Not-A-Number).
isNil (obj) Checks if the given argument is nil.
isNumber (obj) Checks if the given argument is a number.
isString (obj) Checks if the given argument is a string.
isTable (t) Checks if the given arg is a table.
keys (obj) Returns the keys of the object properties.
kvpairs (obj) Converts key-value pairs to an array-list of [k, v] pairs.
obj:value () Extracts the value of a wrapped object.
omit (obj, ...) Returns an object copy without black-listed properties.
path (obj, ...) Returns the value at a given path in an object.
pick (obj, ...) Returns an object copy having white-listed properties.
property (key) Returns a function that will return the key property of any passed-in object.
propertyOf (obj) Returns a function which will return the value of an object property.
result (obj, method) Invokes an object method.
spreadPath (obj, ...) Spreads object under property path onto provided object.
tap (obj, f) Invokes interceptor with the object, and then returns object.
template (obj[, template]) Applies a template to an object, preserving non-nil properties.
toBoolean (value) Converts any given value to a boolean
toObj (kvpairs) Converts an array list of [k,v] pairs to an object.
type (obj) Extends Lua's type function.
values (obj) Returns the values of the object properties.


Operator functions

operator.add (a, b)
Returns a + b. Aliased as op.add.

Parameters:

  • a a value
  • b a value

Returns:

    a + b
operator.concat (a, b)
Returns concatenation of a and b. Aliased as op.concat.

Parameters:

  • a a value
  • b a value

Returns:

    a .. b
operator.div (a, b)
Returns a / b. Aliased as op.div.

Parameters:

  • a a value
  • b a value

Returns:

    a / b
operator.eq (a, b)
Checks if a equals b. Aliased as op.eq.

Parameters:

  • a a value
  • b a value

Returns:

    a == b
operator.exp (a, b)
Returns a ^ b. Aliased as op.exp, op.pow.

Parameters:

  • a a value
  • b a value

Returns:

    a ^ b
operator.floordiv (a, b)
Performs floor division (//) between a and b. It rounds the quotient towards minus infinity. Aliased as op.floordiv.

Parameters:

  • a a value
  • b a value

Returns:

    a // b
operator.ge (a, b)
Returns logical a and b. Aliased as op.land.

Parameters:

  • a a value
  • b a value

Returns:

    a and b
operator.ge (a, b)
Checks if a is greater or equal to b. Aliased as op.ge.

Parameters:

  • a a value
  • b a value

Returns:

    a >= b
operator.gt (a, b)
Checks if a is strictly greater than b. Aliased as op.gt.

Parameters:

  • a a value
  • b a value

Returns:

    a > b
operator.intdiv (a, b)
Performs integer division between a and b. Aliased as op.intdiv.

Parameters:

  • a a value
  • b a value

Returns:

    a / b
operator.le (a, b)
Checks if a is less or equal to b. Aliased as op.le.

Parameters:

  • a a value
  • b a value

Returns:

    a <= b
operator.length (a)
Returns the length of a. Aliased as op.len.

Parameters:

  • a a value

Returns:

    a

operator.lnot (a)
Returns logical not a. Aliased as op.lnot.

Parameters:

  • a a value

Returns:

    not a
operator.lor (a, b)
Returns logical a or b. Aliased as op.lor.

Parameters:

  • a a value
  • b a value

Returns:

    a or b
operator.lt (a, b)
Checks if a is strictly less than b. Aliased as op.lt.

Parameters:

  • a a value
  • b a value

Returns:

    a < b
operator.mod (a, b)
Returns a % b. Aliased as op.mod.

Parameters:

  • a a value
  • b a value

Returns:

    a % b
operator.mul (a, b)
Returns a * b. Aliased as op.mul.

Parameters:

  • a a value
  • b a value

Returns:

    a * b
operator.neq (a, b)
Checks if a not equals b. Aliased as op.neq.

Parameters:

  • a a value
  • b a value

Returns:

    a ~= b
operator.sub (a, b)
Returns a - b. Aliased as op.sub.

Parameters:

  • a a value
  • b a value

Returns:

    a - b
operator.unm (a)
Returns -a. Aliased as op.unm, op.neg.

Parameters:

  • a a value

Returns:

    -a

Table functions

adjust (t, key, f)
Adjusts the value at a given key using a function or a value. In case f is a function, it should be prototyped f(v). It does not mutate the given table, but rather returns a new array. In case the given key does not exist in t, it throws an error.

Parameters:

  • t a table
  • key a key
  • f a function, prototyped as f(v) or a value
all (t, f)
Checks if all values in a table are passing an iterator test.
Aliased as every

Parameters:

  • t a table
  • f an iterator function, prototyped as f (v, k)

Returns:

    true if all values passes the predicate, false otherwise
allEqual (t[, comp])
Checks if all values in a collection are equal. Uses an optional comp function which is used to compare values and defaults to isEqual when not given.
Aliased as alleq.

Parameters:

  • t a table
  • comp a comparison function. Defaults to isEqual (optional)

Returns:

    true when all values in t are equal, false otherwise.

See also:

at (t, ...)
Collects values at given keys and return them wrapped in an array.

Parameters:

  • t a table
  • ... A variable number of keys to collect values

Returns:

    an array-list of values
best (t, f)
Returns the best value passing a selector function. Acts as a special case of reduce, using the first value in t as an initial state. It thens folds the given table, testing each of its values v and selecting the value passing the call f(state,v) every time.

Parameters:

  • t a table
  • f an iterator function, prototyped as f (state, value)

Returns:

    the final state of reduction

See also:

clear (t)
Clears a table. All its values become nil.

Parameters:

  • t a table

Returns:

    the given table, cleared.
containsKeys (t, other)
Checks if all the keys of other table exists in table t. It does not compares values. The test is not commutative, i.e table t may contains keys not existing in other.

Parameters:

  • t a table
  • other another table

Returns:

    true or false

See also:

count (t[, val])
Counts occurrences of a given value in a table. Uses isEqual to compare values.

Parameters:

  • t a table
  • val a value to be searched in the table. If not given, the size of the table will be returned (optional)

Returns:

    the count of occurrences of the given value

See also:

countBy (t, iter)
Groups values in a collection and counts them.

Parameters:

  • t a table
  • iter an iterator function, prototyped as iter (v, k)

Returns:

    a table of subsets groups names paired with their count
countf (t, f)
Counts the number of values passing a predicate test. Same as count, but uses an iterator. Returns the count for values passing the test f (v, k)

Parameters:

  • t a table
  • f an iterator function, prototyped as f (v, k)

Returns:

    the count of values validating the predicate

See also:

cycle (t[, n])
Loops n times through a table. In case n is omitted, it will loop forever. In case n is lower or equal to 0, it returns an empty function.
Aliased as loop.

Parameters:

  • t a table
  • n the number of loops (optional)

Returns:

    an iterator function yielding value-key pairs from the passed-in table.
detect (t, value)
Performs a linear search for a value in a table. Returns the key of the value if found. The given value can be a function prototyped as f (v, value) which should return true when any v in the table equals the value being searched. This function is similar to find, which is mostly meant to work with array.

Parameters:

  • t a table
  • value a value to search for

Returns:

    the key of the value when found or nil

See also:

each (t, f)
Iterates on key-value pairs, calling f (v, k) at every step.
Aliased as forEach.

Parameters:

  • t a table
  • f a function, prototyped as f (v, k)

See also:

eachi (t, f)
Iterates on integer key-value pairs, calling f(v, k) every step.
Only applies to values located at integer keys. The table can be a sparse array. Iteration will start from the lowest integer key found to the highest one.
Aliased as forEachi.

Parameters:

  • t a table
  • f a function, prototyped as f (v, k)

See also:

findWhere (t, props)
Returns the first value having specified keys props.

Parameters:

  • t a table
  • props a set of keys

Returns:

    a value from the passed-in table

See also:

groupBy (t, iter)
Splits a table into subsets groups.

Parameters:

  • t a table
  • iter an iterator function, prototyped as iter (v, k)

Returns:

    a table of subsets groups
include (t, value)
Performs a linear search for a value in a table. It does not work for nested tables. The given value can be a function prototyped as f (v, value) which should return true when any v in the table equals the value being searched.
Aliased as any, some, contains

Parameters:

  • t a table
  • value a value to search for

Returns:

    a boolean : true when found, false otherwise

See also:

invoke (t, method)
Invokes a method on each value in a table.

Parameters:

  • t a table
  • method a function, prototyped as f (v, k)

Returns:

    the result of the call f (v, k)

See also:

map (t, f)
Maps f (v, k) on value-key pairs, collects and returns the results.
Aliased as collect.

Parameters:

  • t a table
  • f an iterator function, prototyped as f (v, k)

Returns:

    a table of results
mapReduce (t, f[, state])
Reduces a table while saving intermediate states. Folds the table left-to-right using a given iterator and an initial state. The iterator takes a state and a value, and returns a new state. The result is an array of intermediate states.
Aliased as mapr

Parameters:

  • t a table
  • f an iterator function, prototyped as f (state, value)
  • state an initial state of reduction. Defaults to the first value in the table. (optional)

Returns:

    an array of states

See also:

mapReduceRight (t, f[, state])
Reduces a table while saving intermediate states. Folds the table right-to-left using a given iterator and an initial state. The iterator takes a state and a value, and returns a new state. The result is an array of intermediate states.
Aliased as maprr

Parameters:

  • t a table
  • f an iterator function, prototyped as f (state, value)
  • state an initial state of reduction. Defaults to the last value in the table. (optional)

Returns:

    an array of states

See also:

max (t[, transform])
Returns the max value in a collection. If a transform function is passed, it will be used to evaluate values by which all objects will be sorted.

Parameters:

  • t a table
  • transform a transformation function, prototyped as transform (v, k), defaults to identity (optional)

Returns:

    the max value found

See also:

min (t[, transform])
Returns the min value in a collection. If a transform function is passed, it will be used to evaluate values by which all objects will be sorted.

Parameters:

  • t a table
  • transform a transformation function, prototyped as transform (v, k), defaults to identity (optional)

Returns:

    the min value found

See also:

pluck (t, key)
Extracts values in a table having a given key.

Parameters:

  • t a table
  • key a key, will be used to index in each value: value[key]

Returns:

    an array of values having the given key
reduce (t, f[, state])
Reduces a table, left-to-right. Folds the table from the first element to the last element to a single value, using a given iterator and an initial state. The iterator takes a state and a value and returns a new state.
Aliased as inject, foldl.

Parameters:

  • t a table
  • f an iterator function, prototyped as f (state, value)
  • state an initial state of reduction. Defaults to the first value in the table. (optional)

Returns:

    the final state of reduction

See also:

reduceBy (t, f, pred[, state[, ...]])
Reduces values in a table passing a given predicate. Folds the table left-to-right, considering only values validating a given predicate.

Parameters:

  • t a table
  • f an iterator function, prototyped as f (state, value)
  • pred a predicate function pred (v, k) to select values to be considered for reduction
  • state an initial state of reduction. Defaults to the first value in the table of selected values. (optional)
  • ... optional args to be passed to pred (optional)

Returns:

    the final state of reduction

See also:

reduceRight (t, f[, state])
Reduces a table, right-to-left. Folds the table from the last element to the first element to single value, using a given iterator and an initial state. The iterator takes a state and a value, and returns a new state.
Aliased as injectr, foldr.

Parameters:

  • t a table
  • f an iterator function, prototyped as f (state, value)
  • state an initial state of reduction. Defaults to the last value in the table. (optional)

Returns:

    the final state of reduction

See also:

reject (t, f)
Clones a table while dropping values passing an iterator test.
Aliased as discard

Parameters:

  • t a table
  • f an iterator function, prototyped as f (v, k)

Returns:

    the remaining values

See also:

same (a, b)
Checks if two tables are the same. It compares if both tables features the same values, but not necessarily at the same keys.

Parameters:

  • a a table
  • b another table

Returns:

    true or false
sameKeys (tA, tB)
Checks if both given tables have the same keys. It does not compares values.

Parameters:

  • tA a table
  • tB another table

Returns:

    true or false

See also:

select (t, f)
Selects and returns values passing an iterator test.
Aliased as filter.

Parameters:

  • t a table
  • f an iterator function, prototyped as f (v, k)

Returns:

    the selected values

See also:

size ([...])
Counts the number of values in a collection. If being passed more than one argument it will return the count of all passed-in arguments.

Parameters:

  • ... Optional variable number of arguments (optional)

Returns:

    a count

See also:

sort (t[, comp])
Sorts a table, in-place. If a comparison function is given, it will be used to sort values.

Parameters:

  • t a table
  • comp a comparison function prototyped as comp (a, b), defaults to < operator. (optional)

Returns:

    the given table, sorted.

See also:

sortBy (t[, transform[, comp]])
Sorts a table in-place using a transform. Values are ranked in a custom order of the results of running transform (v) on all values. transform may also be a string name property sort by. comp is a comparison function.

Parameters:

  • t a table
  • transform a transform function to sort elements prototyped as transform (v). Defaults to identity (optional)
  • comp a comparison function, defaults to the < operator (optional)

Returns:

    a new array of sorted values

See also:

sortedk (t[, comp])
Iterates on values with respect to key order. Keys are sorted using comp function which defaults to math.min. It returns upon each call a key, value pair.

Parameters:

  • t a table
  • comp a comparison function. Defaults to < operator (optional)

Returns:

    an iterator function

See also:

sortedv (t[, comp])
Iterates on values with respect to values order. Values are sorted using comp function which defaults to math.min. It returns upon each call a key, value pair.

Parameters:

  • t a table
  • comp a comparison function. Defaults to < operator (optional)

Returns:

    an iterator function

See also:

where (t, props)
Returns all values having specified keys props.

Parameters:

  • t a table
  • props a set of keys

Returns:

    an array of values from the passed-in table

See also:

Array functions

addTop (array, ...)
Adds all passed-in values at the top of an array. The last elements will bubble to the top of the given array.

Parameters:

  • array an array
  • ... a variable number of arguments

Returns:

    the passed-in array with new values added

See also:

aperture (array[, n])
Iterator returning sliding partitions of an array.
Aliased as sliding

Parameters:

  • array an array
  • n the size of partitions. Defaults to 2 (and then behaves like pairwise) (optional)

Returns:

    an iterator function

See also:

append (array, other)
Clones array and appends values from another array.

Parameters:

  • array an array
  • other an array

Returns:

    a new array
chunk (array, f)
Chunks together consecutive values. Values are chunked on the basis of the return value of a provided predicate f (v, k). Consecutive elements which return the same value are chunked together. Leaves the first argument untouched if it is not an array.

Parameters:

  • array an array
  • f an iterator function prototyped as f (v, k)

Returns:

    a table of chunks (arrays)

See also:

compact (array)
Returns all truthy values (removes falses and nils).

Parameters:

  • array an array

Returns:

    a new array
concat (array[, sep[, i[, j]]])
Concatenates values in a given array. Handles booleans as well. If sep string is passed, it will be used as a separator. Passing i and j will result in concatenating only values within [i, j] range.
Aliased as join

Parameters:

  • array a given array
  • sep a separator string, defaults to the empty string ''. (optional)
  • i the starting index, defaults to 1. (optional)
  • j the final index, defaults to the array length. (optional)

Returns:

    a string
difference (array, another)
Returns values from an array not present in all passed-in args.
Aliased as without and diff

Parameters:

  • array an array
  • another array

Returns:

    a new array

See also:

disjoint (...)
Checks if all passed in arrays are disjunct.

Parameters:

  • ... a variable number of arrays

Returns:

    true if the intersection of all arrays is not empty, false otherwise.

See also:

dropWhile (array, f)
Collects values from a given array. The passed-in array should not be sparse. This function collects values as long as they do not satisfy a given predicate and returns on the first truthy test.
Aliased as rejectWhile

Parameters:

  • array an array
  • f an iterator function prototyped as f (v, k)

Returns:

    a new table containing all values collected

See also:

duplicates (array)
Returns an array list of all duplicates in array.

Parameters:

  • array an array

Returns:

    an array-list of duplicates

See also:

fill (array, value[, i[, j]])
Replaces elements in a given array with a given value. In case i and j are given it will only replaces values at indexes between [i,j]. In case j is greater than the array size, it will append new values, increasing the array size.

Parameters:

  • array an array
  • value a value
  • i the index from which to start replacing values. Defaults to 1. (optional)
  • j the index where to stop replacing values. Defaults to the array size. (optional)

Returns:

    the original array with values changed
find (array, value[, from])
Looks for the first occurrence of a given value in an array. Returns the value index if found. Uses isEqual to compare values.

Parameters:

  • array an array of values
  • value a value to lookup for
  • from the index from where the search will start. Defaults to 1. (optional)

Returns:

    the index of the value if found in the array, nil otherwise.

See also:

findIndex (array, pred)
Returns the first index at which a predicate returns true.

Parameters:

  • array an array
  • pred a predicate function prototyped as pred (v, k)

Returns:

    the index found or nil

See also:

findLastIndex (array, pred)
Returns the last index at which a predicate returns true.

Parameters:

  • array an array
  • pred a predicate function prototyped as pred (k, v)

Returns:

    the index found or nil

See also:

first (array[, n])
Returns the first N values in an array.
Aliased as head, take

Parameters:

  • array an array
  • n the number of values to be collected, defaults to 1. (optional)

Returns:

    a new array

See also:

flatten (array[, shallow])
Flattens a nested array. Passing shallow will only flatten at the first level.

Parameters:

  • array an array
  • shallow specifies the flattening depth. Defaults to false.` (optional)

Returns:

    a flattened array
indexOf (array, value)
Returns the index of the first occurrence of value in an array.

Parameters:

  • array an array
  • value the value to search for

Returns:

    the index of the passed-in value

See also:

initial (array[, n])
Returns all values in an array excluding the last N values.

Parameters:

  • array an array
  • n the number of values to be left, defaults to the array length. (optional)

Returns:

    a new array

See also:

interleave (...)
Interleaves arrays. It returns a single array made of values from all passed in arrays in their given order, interleaved.

Parameters:

  • ... a variable list of arrays

Returns:

    a new array

See also:

interpose (array, value)
Interposes value in-between consecutive pair of values in array.
Aliased as intersperse

Parameters:

  • array an array
  • value a value

Returns:

    a new array

See also:

intersection (...)
Returns the intersection of all passed-in arrays. Each value in the result is present in each of the passed-in arrays.

Parameters:

  • ... a variable number of array arguments

Returns:

    a new array

See also:

isunique (array)
Checks if a given array contains distinct values. Such an array is made of distinct elements, which only occur once in this array.
Aliased as isuniq

Parameters:

  • array an array

Returns:

    true if the given array is unique, false otherwise.

See also:

last (array[, n])
Returns the last N values in an array.

Parameters:

  • array an array
  • n the number of values to be collected, defaults to the array length. (optional)

Returns:

    a new array

See also:

lastIndexOf (array, value)
Returns the index of the last occurrence of value in an array.

Parameters:

  • array an array
  • value the value to search for

Returns:

    the index of the last occurrence of the passed-in value or nil

See also:

mean (array)
Returns the mean of an array of numbers.
Aliased as average

Parameters:

  • array an array of numbers

Returns:

    a number

See also:

median (array)
Returns the median of an array of numbers.

Parameters:

  • array an array of numbers

Returns:

    a number

See also:

nsorted (array[, n[, comp]])
Returns the n-top values satisfying a predicate. It takes a comparison function comp used to sort array values, and then picks the top n-values. It leaves the original array untouched.

Parameters:

  • array an array
  • n a number of values to retrieve. Defaults to 1. (optional)
  • comp a comparison function. Defaults to < operator. (optional)

Returns:

    an array of top n values
nth (array, index)
Returns the value at a given index.

Parameters:

  • array an array
  • index an index

Returns:

    the value at the given index
ones (n)
Returns an array of n 1's.

Parameters:

  • n a number

Returns:

    an array

See also:

overlapping (array[, n[, pads]])
Iterator returning overlapping partitions of an array.
If the last subsequence has lower elements than n and pad is supplied, it will be adjusted to n elements with pad value.

Parameters:

  • array an array
  • n the size of partitions. Defaults to 2. (optional)
  • pads a value to adjust the last subsequence to the n elements (optional)

Returns:

    an iterator function

See also:

pack (...)
Converts a list of arguments to an array.

Parameters:

  • ... a list of arguments

Returns:

    an array of all passed-in args
pairwise (array)
Iterator returning sliding pairs of an array.

Parameters:

  • array an array

Returns:

    an iterator function

See also:

partition (array[, n[, pads]])
Iterator returning partitions of an array. It returns arrays of length n made of values from the given array. If the last partition has lower elements than n and pad is supplied, it will be adjusted to n of elements with pad value.

Parameters:

  • array an array
  • n the size of partitions. Defaults to 1. (optional)
  • pads a value to adjust the last subsequence to the n elements (optional)

Returns:

    an iterator function

See also:

permutation (array)
Iterator returning the permutations of an array. It returns arrays made of all values from the passed-in array, with values permuted.

Parameters:

  • array an array

Returns:

    an iterator function
powerset (array)
Returns the powerset of array values. For instance, when given the set {1,2,3}, returns {{1},{2},{3},{1,2},{2,3},{1,2,3}}.

Parameters:

  • array an array

Returns:

    an array
prepend (array, ...)
Adds all passed-in values at the top of an array. As opposed to addTop, it preserves the order of the passed-in elements.

Parameters:

  • array an array
  • ... a variable number of arguments

Returns:

    the passed-in array with new values added

See also:

product (array)
Returns the product of array values.

Parameters:

  • array a given array

Returns:

    the product of array values
pull (array, ...)
Removes all provided values in a given array.
Aliased as remove

Parameters:

  • array an array
  • ... a variable number of values to be removed from the array

Returns:

    the passed-in array with values removed
push (array, ...)
Pushes all passed-in values at the end of an array.

Parameters:

  • array an array
  • ... a variable number of arguments

Returns:

    the passed-in array with new added values

See also:

range ([from[, to[, step]]])
Produces a flexible list of numbers. If one value is passed, will count from 1 to that value, with a default step of 1 (or -1). If two values are passed, will count from the first one to the second one, using a default step of 1 (or -1). A third value passed will be considered a step value.

Parameters:

  • from the initial value of the range (optional)
  • to the final value of the range (optional)
  • step the step of count. Defaults to 1 or -1. (optional)

Returns:

    a new array of numbers
removeRange (array[, start[, finish]])
Removes values at an index within the range [start, finish].
Aliased as rmRange, chop

Parameters:

  • array an array
  • start the lower bound index, defaults to the first index in the array. (optional)
  • finish the upper bound index, defaults to the array length. (optional)

Returns:

    the passed-in array with values removed
rep (value, n)
Creates an array list of n values, repeated.

Parameters:

  • value a value to be repeated
  • n the number of repetitions of value.

Returns:

    a new array of n values
rest (array[, index])
Returns all values after index.
Aliased as tail

Parameters:

  • array an array
  • index an index, defaults to 1 (optional)

Returns:

    a new array

See also:

reverse (array)
Returns an array where values are in reverse order. The passed-in array should not be sparse.

Parameters:

  • array an array

Returns:

    a reversed array
sample (array[, n[, seed]])
Samples n random values from an array. If n is not specified, returns a single element. It uses internally shuffle to shuffle the array before sampling values. If seed is passed, it will be used for shuffling.

Parameters:

  • array an array
  • n a number of elements to be sampled. Defaults to 1. (optional)
  • seed an optional seed for shuffling (optional)

Returns:

    an array of selected values

See also:

sampleProb (array, prob[, seed])
Return elements from a sequence with a given probability. It considers each value independently. Providing a seed will result in deterministic sampling. Given the same seed it will return the same sample every time.

Parameters:

  • array an array
  • prob a probability for each element in array to be selected
  • seed an optional seed for deterministic sampling (optional)

Returns:

    an array of selected values

See also:

selectWhile (array, f)
Collects values from a given array. The passed-in array should not be sparse. This function collects values as long as they satisfy a given predicate and returns on the first falsy test.
Aliased as takeWhile

Parameters:

  • array an array
  • f an iterator function prototyped as f (v, k)

Returns:

    a new table containing all values collected

See also:

shift (array[, n])
Removes and returns the values at the top of a given array.
Aliased as pop

Parameters:

  • array an array
  • n the number of values to be popped. Defaults to 1. (optional)

Returns:

    the popped values

See also:

shuffle (array[, seed])
Returns a shuffled copy of a given array. If a seed is provided, it will be used to init the built-in pseudo random number generator (using math.randomseed).

Parameters:

  • array an array
  • seed a seed (optional)

Returns:

    a shuffled copy of the given array
slice (array[, start[, finish]])
Slices values indexed within [start, finish] range.
Aliased as M.sub

Parameters:

  • array an array
  • start the lower bound index, defaults to the first index in the array. (optional)
  • finish the upper bound index, defaults to the array length. (optional)

Returns:

    a new array of sliced values
sortedIndex (array, the[, comp[, sort]])
Returns the index at which a value should be inserted. This index is evaluated so that it maintains the sort. If a comparison function is passed, it will be used to sort values.

Parameters:

  • array an array
  • the value to be inserted
  • comp an comparison function prototyped as f (a, b), defaults to < operator. (optional)
  • sort whether or not the passed-in array should be sorted (optional)

Returns:

    number the index at which the passed-in value should be inserted
sum (array)
Returns the sum of array values.

Parameters:

  • array a given array

Returns:

    the sum of array values
symmetricDifference (array, array2)
Performs a symmetric difference. Returns values from array not present in array2 and also values from array2 not present in array.
Aliased as symdiff

Parameters:

  • array an array
  • array2 another array

Returns:

    a new array

See also:

union (...)
Returns the duplicate-free union of all passed in arrays.

Parameters:

  • ... a variable number of arrays arguments

Returns:

    a new array

See also:

unique (array)
Produces a duplicate-free version of a given array.
Aliased as uniq

Parameters:

  • array an array

Returns:

    a new array, duplicate-free

See also:

unshift (array[, n])
Removes and returns the values at the end of a given array.

Parameters:

  • array an array
  • n the number of values to be unshifted. Defaults to 1. (optional)

Returns:

    the values

See also:

vector (value, n)
Returns an array of n times a given value.

Parameters:

  • value a value
  • n a number

Returns:

    an array

See also:

xpairs (valua, array)
Creates pairs from value and array. Value is always prepended to the pair.

Parameters:

  • valua a value
  • array an array

Returns:

    an array list of all pairs
xpairsRight (valua, array)
Creates pairs from value and array. Value is always appended as the last item to the pair.

Parameters:

  • valua a value
  • array an array

Returns:

    an array list of all pairs
xprod (array, array2)
Returns all possible pairs built from given arrays.

Parameters:

  • array a first array
  • array2 a second array

Returns:

    an array list of all pairs
zeros (n)
Returns an array of n zeros.

Parameters:

  • n a number

Returns:

    an array

See also:

zip (...)
Merges values of each of the passed-in arrays in subsets. Only values indexed with the same key in the given arrays are merged in the same subset.
Aliased as transpose

Parameters:

  • ... a variable number of array arguments

Returns:

    a new array

See also:

zipWith (f, ...)
Merges values using a given function. Only values indexed with the same key in the given arrays are merged in the same subset. Function f is used to combine values.
Aliased as transposeWith

Parameters:

  • f a function
  • ... a variable number of array arguments

Returns:

    a flat array of results

See also:

Utility functions

after (f, count)
Returns a version of f that runs on the count-th call. Useful when dealing with asynchronous tasks.

Parameters:

  • f a function
  • count the number of calls before f will start running.

Returns:

    a new function

See also:

applySpec (specs)
Returns a function which applies specs on args. This function produces an object having the same structure than specs by mapping each property to the result of calling its associated function with the supplied arguments

Parameters:

  • specs a table

Returns:

    a function
ary (f[, n])
Returns a function which accepts up to n args. It ignores any additional arguments.
Aliased as nAry.

Parameters:

  • f a function
  • n a number. Defaults to 1. (optional)

Returns:

    a function

See also:

before (f, count)
Returns a version of f that will run no more than count times. Next calls will keep yielding the results of the count-th call.

Parameters:

  • f a function
  • count a count

Returns:

    a new function

See also:

bind (f, v)
Binds v to be the first argument to f. Calling f (...) will result to f (v, ...).

Parameters:

  • f a function
  • v a value

Returns:

    a function

See also:

bind2 (f, v)
Binds v to be the second argument to f. Calling f (a, ...) will result to f (a, v, ...).

Parameters:

  • f a function
  • v a value

Returns:

    a function

See also:

bindall (obj, ...)
Binds methods to object. As such, whenever any of these methods is invoked, it always receives the object as its first argument.

Parameters:

  • obj an abject
  • ... a variable number of method names

Returns:

    the passed-in object with all methods bound to the object itself.

See also:

bindn (f, ...)
Binds ... to be the N-first arguments to function f.
Calling f (a1, a2, ..., aN) will result to f (..., a1, a2, ...,aN).

Parameters:

  • f a function
  • ... a variable number of arguments

Returns:

    a function

See also:

both (...)
Returns a validation function. Given a set of functions, the validation function evaluates to true only when all its funcs returns true.

Parameters:

  • ... an array list of functions

Returns:

    true when all given funcs returns true with input, false otherwise
call (f[, ...])
Calls f with the supplied arguments. Returns the results of f(...).

Parameters:

  • f a function
  • ... a vararg list of args to f (optional)

Returns:

    the result of f(...) call.
castArray (value)
Casts value as an array if it is not one.

Parameters:

  • value a value

Returns:

    an array containing the given value
complement (f)
Returns the logical complement of a given function. For a given input, the returned function will output false if the original function would have returned true, and vice-versa.

Parameters:

  • f a function

Returns:

    the logical complement of the given function f.
compose (...)
Composes functions. Each passed-in function consumes the return value of the function that follows. In math terms, composing the functions f, g, and h produces the function f(g(h(...))).

Parameters:

  • ... a variable number of functions

Returns:

    a new function

See also:

cond (conds)
Returns a function which iterate over a set of conditions. It invokes each predicate, passing it given values. It returns the value of the corresponding function of the first predicate to return a non-nil value.

Parameters:

  • conds an array list of predicate-function pairs

Returns:

    the result of invoking f(...) of the first predicate to return a non-nil value
constant (value)
Creates a constant function which returns the same output on every call.
Aliased as always

Parameters:

  • value a constant value

Returns:

    a constant function
converge (f, g, h)
Converges two functions into one.

Parameters:

  • f a function
  • g a function
  • h a function

Returns:

    a new version of function f
curry (f[, n_args])
Curries a function. If the given function f takes multiple arguments, it returns another version of f that takes a single argument (the first of the arguments to the original function) and returns a new function that takes the remainder of the arguments and returns the result.

Parameters:

  • f a function
  • n_args the number of arguments expected for f. Defaults to 2. (optional)

Returns:

    a curried version of f

See also:

dispatch (...)
Returns a dispatching function. When called with arguments, this function invokes each of its functions in the passed-in order and returns the results of the first non-nil evaluation.

Parameters:

  • ... a vararg list of functions

Returns:

    a dispatch function
either (...)
Returns a validation function. Given a set of functions, the validation function evaluates to true when at least one of its funcs returns true.

Parameters:

  • ... an array list of functions

Returns:

    true when one of the given funcs returns true with input, false otherwise
flip (f)
Creates a function of f with arguments flipped in reverse order.

Parameters:

  • f a function

Returns:

    a function
identity (value)
Returns the passed-in value. This function is used internally as a default iterator.

Parameters:

  • value a value

Returns:

    the passed-in value
iterator (f, value[, n])
Produces an iterator which repeatedly apply a function f onto an input.
Yields value, then f(value), then f(f(value)), continuously.
Aliased as iter.

Parameters:

  • f a function
  • value an initial input to f
  • n the number of times the iterator should run (optional)

Returns:

    an iterator function
iterlen (...)
Returns the length of an iterator. It consumes the iterator itself.

Parameters:

  • ... an iterator function (returning a generator, a state and a value)

Returns:

    the iterator length
juxtapose (value, ...)
Calls a sequence of passed-in functions with the same argument. Returns a sequence of results.
Aliased as juxt

Parameters:

  • value a value
  • ... a variable number of functions

Returns:

    a list of results
memoize (f)
Memoizes a given function by caching the computed result. Useful for speeding-up slow-running functions.
Aliased as cache

Parameters:

  • f a function

Returns:

    a new function
neither (...)
Returns a validation function. Given a set of functions, the validation function evaluates to true when neither of its func return true.

Parameters:

  • ... an array list of functions

Returns:

    true when neither of the given funcs returns true with input, false otherwise
noarg (f)
Returns a function with an arity of 0. The new function ignores any arguments passed to it.

Parameters:

  • f a function

Returns:

    a new function
noop ()
The no operation function.

Returns:

    nothing
nthArg (n)
Returns a function that gets the nth argument.
If n is negative, the nth argument from the end is returned.

Parameters:

  • n a number

Returns:

    a function
once (f)
Returns a version of f that runs only once. Successive calls to f will keep yielding the same output, no matter what the passed-in arguments are. It can be used to initialize variables.

Parameters:

  • f a function

Returns:

    a new function

See also:

over (...)
Creates a function that runs transforms on all arguments it receives.

Parameters:

  • ... a set of functions which will receive all arguments to the returned function

Returns:

    a function

See also:

overArgs (f, ...)
Creates a function that invokes f with its arguments transformed. 1rst arguments will be passed to the 1rst transform, 2nd arg to the 2nd transform, etc. Remaining arguments will not be transformed.

Parameters:

  • f a function
  • ... a list of transforms funcs prototyped as f (v)

Returns:

    the result of running f with its transformed arguments

See also:

overEvery (...)
Creates a validation function. The returned function checks if all of the given predicates return truthy when invoked with the arguments it receives.

Parameters:

  • ... a list of predicate functions

Returns:

    a new function

See also:

overSome (...)
Creates a validation function. The return function checks if any of a given predicates return truthy when invoked with the arguments it receives.

Parameters:

  • ... a list of predicate functions

Returns:

    a new function

See also:

partial (f, ...)
Partially apply a function by filling in any number of its arguments.
One may pass a string 'M' as a placeholder in the list of arguments to specify an argument that should not be pre-filled, but left open to be supplied at call-time.

Parameters:

  • f a function
  • ... a list of partial arguments to f

Returns:

    a new version of function f having some of it original arguments filled

See also:

partialRight (f, ...)
Similar to partial, but from the right.

Parameters:

  • f a function
  • ... a list of partial arguments to f

Returns:

    a new version of function f having some of it original arguments filled

See also:

pipe (value, ...)
Pipes a value through a series of functions. In math terms, given some functions f, g, and h in that order, it returns f(g(h(value))).

Parameters:

  • value a value
  • ... a variable number of functions

Returns:

    the result of the composition of function calls.

See also:

rearg (f, indexes)
Returns a function which runs with arguments rearranged. Arguments are passed to the returned function in the order of supplied indexes at call-time.

Parameters:

  • f a function
  • indexes an array list of indexes

Returns:

    a function
skip (iter[, n])
Consumes the first n values of a iterator then returns it.

Parameters:

  • iter an iterator function
  • n a number. Defaults to 1. (optional)

Returns:

    the given iterator
tabulate (...)
Iterates over an iterator and returns its values in an array.

Parameters:

  • ... an iterator function (returning a generator, a state and a value)

Returns:

    an array of results
thread (value, ...)
Threads value through a series of functions. If a function expects more than one args, it can be specified using an array list, where the first item is the function and the following are the remaining args neeeded. The value is used as the first input.

Parameters:

  • value a value
  • ... a vararg list of functions or arrays

Returns:

    a value

See also:

threadRight (value, ...)
Threads value through a series of functions. If a function expects more than one args, it can be specified using an array list, where the first item is the function and the following are the remaining args neeeded. The value is used as the last input.

Parameters:

  • value a value
  • ... a vararg list of functions or arrays

Returns:

    a value

See also:

time (f[, ...])
Returns the execution time of f (...) and its returned values.

Parameters:

  • f a function
  • ... optional args to f (optional)

Returns:

    the execution time and the results of f (...)
times (iter[, n])
Runs iter function n times. Collects the results of each run and returns them in an array.

Parameters:

  • iter an iterator function, prototyped as iter (i)
  • n the number of times iter should be called. Defaults to 1. (optional)

Returns:

    table an array of results
unary (f)
Returns a function which accepts up to one arg. It ignores any additional arguments.

Parameters:

  • f a function

Returns:

    a function

See also:

unfold (f, seed)
Builds a list from a seed value. Accepts an iterator function, which returns either nil to stop iteration or two values : the value to add to the list of results and the seed to be used in the next call to the iterator function.

Parameters:

  • f an iterator function
  • seed a seed value

Returns:

    an array of values
uniqueId ([template])
Generates an unique ID for the current session. If given a string template, it will use this template for output formatting. Otherwise, if template is a function, it will evaluate template (id).
Aliased as uid.

Parameters:

  • template either a string or a function template to format the ID (optional)

Returns:

    value an ID
wrap (f, wrapper)
Wraps f inside of the wrapper function. It passes f as the first argument to wrapper. This allows the wrapper to execute code before and after f runs, adjust the arguments, and execute it conditionally.

Parameters:

  • f a function to be wrapped, prototyped as f (...)
  • wrapper a wrapper function, prototyped as wrapper (f, ...)

Returns:

    the results

Object functions

chain (value)
Returns a wrapped object. Calling library functions as methods on this object will continue to return wrapped objects until obj:value is used. Can be aliased as M(value).

Parameters:

  • value a value to be wrapped

Returns:

    a wrapped object
clone (obj[, shallow])
Clones a given object properties. If shallow is passed will also clone nested array properties.

Parameters:

  • obj an object
  • shallow whether or not nested array-properties should be cloned, defaults to false. (optional)

Returns:

    a copy of the passed-in object
extend (destObj, ...)
Extends an object properties. It copies the properties of extra passed-in objects into the destination object, and returns the destination object. The last objects will override properties of the same name.

Parameters:

  • destObj a destination object
  • ... a list of objects

Returns:

    the destination object extended
flattenPath (obj, ...)
Flattens object under property path onto provided object.
It is similar to spreadPath, but preserves object under the property path.

Parameters:

  • obj an object
  • ... a property path given as a vararg list

Returns:

    the passed-in object with changes

See also:

functions ([obj])
Returns a sorted list of all methods names found in an object. If the given object has a metatable implementing an __index field pointing to another table, will also recurse on this table if recurseMt is provided. If obj is omitted, it defaults to the library functions.
Aliased as methods.

Parameters:

  • obj an object. Defaults to Moses library functions. (optional)

Returns:

    an array-list of methods names
has (obj, key)
Checks if a given object implements a property.

Parameters:

  • obj an object
  • key a key property to be checked

Returns:

    true or false
import ([context[, noConflict]])
Imports all library functions into a context.

Parameters:

  • context a context. Defaults to _ENV or _G`` (current environment). (optional)
  • noConflict if supplied, will not import conflicting functions in the destination context. (optional)

Returns:

    the passed-in context
invert (obj)
Swaps keys with values. Produces a new object where previous keys are now values, while previous values are now keys.
Aliased as mirror

Parameters:

  • obj a given object

Returns:

    a new object
isArray (obj)
Checks if the given argument is an array. Assumes obj is an array if is a table with consecutive integer keys starting at 1.

Parameters:

  • obj an object

Returns:

    true or false
isBoolean (obj)
Checks if the given argument is a boolean.

Parameters:

  • obj an object

Returns:

    true or false
isCallable (obj)
Checks if the given argument is callable. Assumes obj is callable if it is either a function or a table having a metatable implementing __call metamethod.

Parameters:

  • obj an object

Returns:

    true or false
isEmpty ([obj])
Checks if the given pbject is empty. If obj is a string, will return true if #obj == 0. Otherwise, if obj is a table, will return whether or not this table is empty. If obj is nil, it will return true.

Parameters:

  • obj an object (optional)

Returns:

    true or false
isEqual (objA, objB[, useMt])
Performs a deep comparison test between two objects. Can compare strings, functions (by reference), nil, booleans. Compares tables by reference or by values. If useMt is passed, the equality operator == will be used if one of the given objects has a metatable implementing __eq.
Aliased as M.compare, M.matches

Parameters:

  • objA an object
  • objB another object
  • useMt whether or not __eq should be used, defaults to false. (optional)

Returns:

    true or false

See also:

isFinite (obj)
Checks if the given argument is a finite number.

Parameters:

  • obj an object

Returns:

    true or false
isFunction (obj)
Checks if the given argument is a function.

Parameters:

  • obj an object

Returns:

    true or false
isInteger (obj)
Checks if the given argument is an integer.

Parameters:

  • obj an object

Returns:

    true or false
isIterable (obj)
Checks if the given object is iterable with pairs (or ipairs).

Parameters:

  • obj an object

Returns:

    true if the object can be iterated with pairs (or ipairs), false otherwise
isNaN (obj)
Checks if the given argument is NaN (see Not-A-Number).

Parameters:

  • obj an object

Returns:

    true or false

See also:

isNil (obj)
Checks if the given argument is nil.

Parameters:

  • obj an object

Returns:

    true or false
isNumber (obj)
Checks if the given argument is a number.

Parameters:

  • obj an object

Returns:

    true or false

See also:

isString (obj)
Checks if the given argument is a string.

Parameters:

  • obj an object

Returns:

    true or false
isTable (t)
Checks if the given arg is a table.

Parameters:

  • t a value to be tested

Returns:

    true or false
keys (obj)
Returns the keys of the object properties.

Parameters:

  • obj an object

Returns:

    an array
kvpairs (obj)
Converts key-value pairs to an array-list of [k, v] pairs.

Parameters:

  • obj an object

Returns:

    an array list of key-value pairs

See also:

obj:value ()
Extracts the value of a wrapped object. Must be called on an chained object (see chain).

Returns:

    the value previously wrapped
omit (obj, ...)
Returns an object copy without black-listed properties.
Aliased as drop.

Parameters:

  • obj an object
  • ... a variable number of string keys

Returns:

    the filtered object
path (obj, ...)
Returns the value at a given path in an object.
Path is given as a vararg list of keys.

Parameters:

  • obj an object
  • ... a vararg list of keys

Returns:

    a value or nil
pick (obj, ...)
Returns an object copy having white-listed properties.
Aliased as choose.

Parameters:

  • obj an object
  • ... a variable number of string keys

Returns:

    the filtered object
property (key)
Returns a function that will return the key property of any passed-in object.

Parameters:

  • key a key property name

Returns:

    a function which should accept an object as argument

See also:

propertyOf (obj)
Returns a function which will return the value of an object property.

Parameters:

  • obj an object

Returns:

    a function which should accept a key property argument

See also:

result (obj, method)
Invokes an object method. It passes the object itself as the first argument. if method is not callable, will return obj[method].

Parameters:

  • obj an object
  • method a string key to index in object obj.

Returns:

    the returned value of method (obj) call
spreadPath (obj, ...)
Spreads object under property path onto provided object.
It is similar to flattenPath, but removes object under the property path.

Parameters:

  • obj an object
  • ... a property path given as a vararg list

Returns:

    the passed-in object with changes

See also:

tap (obj, f)
Invokes interceptor with the object, and then returns object. The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.

Parameters:

  • obj an object
  • f an interceptor function, should be prototyped as f (obj)

Returns:

    the passed-in object
template (obj[, template])
Applies a template to an object, preserving non-nil properties.
Aliased as defaults.

Parameters:

  • obj an object
  • template a template object. If nil, leaves obj untouched. (optional)

Returns:

    the passed-in object filled
toBoolean (value)
Converts any given value to a boolean

Parameters:

  • value a value. Can be of any type

Returns:

    true if value is true, false otherwise (false or nil).
toObj (kvpairs)
Converts an array list of [k,v] pairs to an object. Keys are taken from the 1rst column in the [k,v] pairs sequence, associated with values in the 2nd column.

Parameters:

  • kvpairs an array-list of [k,v] pairs

Returns:

    an object

See also:

type (obj)
Extends Lua's type function. It returns the type of the given object and also recognises file userdata

Parameters:

  • obj an object

Returns:

    the given object type
values (obj)
Returns the values of the object properties.

Parameters:

  • obj an object

Returns:

    an array of values
generated by LDoc 1.4.6 Last updated 2018-09-12 11:33:43