Mc.collections namespace provides utility functions for arrays and associative arrays
Iterates over a collection and runs a provided function on each item in the collection.
argument name |
type |
defaultValue |
description |
collection |
dynamic |
- |
The collection to iterate over. Can be an array or a dictionary. |
func |
function |
- |
The function to run on each item. For an array, the function should have the form function(item) , for a dictionary the form should be function(key, value) . |
mTarget |
mc.types.assocarray |
invalid |
The component scope to inject. If not provided, the current component scope will be used. |
Creates a new array with the results of calling a provided function on every element in the input array.
argument name |
type |
defaultValue |
description |
array |
mc.types.array |
- |
The array of items to map. |
mapper |
mc.collections.BaseMapper |
- |
The mapper to use for transformation. Can be a function with the form (transform):outputType , a class with a transform(item):outputType function, or an instance of a class with a transform(item):outputType function. |
mTarget |
mc.types.assocarray |
invalid |
The component scope to inject. If not provided, the current component scope will be used. |
Sorts an array of items based on the unique value at a specified key path.
argument name |
type |
defaultValue |
description |
arr |
mc.types.array |
- |
The array to sort. |
keyPath |
string |
- |
The path to the value to sort on. |
ascending |
boolean |
true |
A boolean indicating whether to sort in ascending order. |
Sorts an array of items based on the result of calling a provided function on each item in the array.
argument name |
type |
defaultValue |
description |
arr |
mc.types.array |
- |
The array to sort. |
func |
function |
- |
The function to use for sorting. The function should have the form function(item) and return a string. |
ascending |
boolean |
true |
A boolean indicating whether to sort in ascending order. |
mTarget |
mc.types.assocarray |
invalid |
The component scope to inject. If not provided, the current component scope will be used. |
Sorts an array of items based on the result of calling a specified function on each item in the array.
argument name |
type |
defaultValue |
description |
arr |
mc.types.array |
- |
The array to sort. |
funcName |
string |
- |
The name of the function to call on each item in the array. The function should return a string. |
ascending |
boolean |
true |
A boolean indicating whether to sort in ascending order. |
Returns the item in an array at a specified offset from a given item.
argument name |
type |
defaultValue |
description |
array |
mc.types.array |
- |
The array to search. |
item |
dynamic |
- |
The item to search for. |
offset |
integer |
- |
The offset from the given item to return. |
key |
string |
invalid |
An optional key to use for searching for the item in the array. |
wrap |
boolean |
false |
A boolean indicating whether to wrap around to the beginning of the array if the offset would take the index past the end of the array. |
Returns the index of a given item in an array.
argument name |
type |
defaultValue |
description |
array |
mc.types.array |
- |
The array to search. |
item |
dynamic |
- |
The item to search for. |
key |
string |
invalid |
An optional key to use for searching for the item in the array. |
Creates a new array with all items that pass the test implemented by the provided function.
argument name |
type |
defaultValue |
description |
array |
mc.types.array |
- |
The array of items to filter. |
predicate |
dynamic |
- |
The predicate to use for filtering. Can be a function with the form (item):bool , a class with a isMatch(item):bool function, or an instance of a class with a isMatch(item):bool function. |
findAll |
boolean |
true |
A boolean indicating whether to return all matching items or just the first. |
mTarget |
mc.types.assocarray |
invalid |
The component scope to inject. If not provided, the current component scope will be used. |
Returns the first item in an array that matches a provided predicate.
argument name |
type |
defaultValue |
description |
array |
mc.types.array |
- |
The array of items to search. |
predicate |
dynamic |
- |
The predicate to use for searching. Can be a function with the form (item):bool , a class with a isMatch(item):bool function, or an |
default |
dynamic |
invalid |
The default value to return if no matching item is found. |
mTarget |
mc.types.assocarray |
invalid |
The component scope to inject. If not provided, the current component scope will be used. |
Returns a boolean indicating whether an array contains an item that matches a provided predicate.
argument name |
type |
defaultValue |
description |
array |
mc.types.array |
- |
The array of items to search. |
predicate |
dynamic |
- |
The predicate to use for searching. Can be a function with the form (item):bool , a class with a isMatch(item):bool function, or an instance of a class with a isMatch(item):bool function. |
mTarget |
mc.types.assocarray |
invalid |
The component scope to inject. If not provided, the current component scope will be used. |
A function that returns a boolean indicating whether the provided array contains the provided value.
argument name |
type |
defaultValue |
description |
array |
mc.types.array |
N/A |
The array to check for the value. |
value |
dynamic |
N/A |
The value to search for in the array. |
An abstract class that defines the transform
function that should be implemented by its derived classes.
method name |
description |
transform(item) |
A function that takes in an item and returns a transformed item. |
A class that derives from BaseMapper
and implements the transform
function by calling a function on the provided item using the callFunc
method.
argument name |
type |
defaultValue |
description |
funcName |
string |
N/A |
The name of the function to call on the item. |
args |
mc.types.assocarray |
N/A |
An associative array of arguments to pass to the function. |
method name |
description |
transform(item) |
A function that takes in an item and returns the result of calling the specified function on the item with the provided arguments. |
A class that derives from BaseMapper
and implements the transform
function by calling a function on the provided item.
argument name |
type |
defaultValue |
description |
funcName |
string |
N/A |
The name of the function to call on the item. |
method name |
description |
transform(item) |
A function that takes in an item and returns the result of calling the specified function on the item. |
A class that derives from BaseMapper
and implements the transform
function by returning the value of a field on the provided item.
argument name |
type |
defaultValue |
description |
fieldName |
string |
N/A |
The name of the field to return the value of. |
method name |
description |
transform(item) |
A function that takes in an item and returns the value of the specified field on the item. |
An abstract class that represents a predicate that can be used to filter items in an array.
property name |
type |
description |
expected |
dynamic |
The expected value for the predicate. |
method name |
return type |
description |
isMatch |
boolean |
A method that returns a boolean indicating whether the provided item matches the expected value for the predicate. |
argument name |
type |
defaultValue |
description |
expected |
dynamic |
N/A |
The expected value for the predicate. |
A class that represents a predicate that filters items by matching their value.
property name |
type |
description |
expected |
dynamic |
The expected value for the predicate. |
method name |
return type |
description |
isMatch |
boolean |
A method that returns a boolean indicating whether the provided item matches the expected value for the predicate. |
argument name |
type |
defaultValue |
description |
expected |
dynamic |
N/A |
The expected value for the predicate. |
A class that represents a predicate that filters items by matching the value of a specific field.
property name |
type |
description |
expected
|
dynamic |
The expected value for the predicate. |
fieldName |
string |
The name of the field to use for matching. |
method name |
return type |
description |
isMatch |
boolean |
A method that returns a boolean indicating whether the provided item matches the expected value for the predicate. |
argument name |
type |
defaultValue |
description |
fieldName |
string |
N/A |
The name of the field to use for matching. |
expected |
dynamic |
N/A |
The expected value for the predicate. |
A class that represents a predicate that filters items by matching the value returned by a specific function.
property name |
type |
description |
expected |
dynamic |
The expected value for the predicate. |
funcName |
string |
The name of the function to call on the item. |
method name |
return type |
description |
isMatch |
boolean |
A method that returns a boolean indicating whether the provided item matches the expected value for the predicate. |
argument name |
type |
defaultValue |
description |
funcName |
string |
N/A |
The name of the function to call on the item. |
expected |
dynamic |
N/A |
The expected value for the predicate. |
A class that represents a predicate that filters items by calling a specific function on them with provided arguments and matching the return value.
property name |
type |
description |
expected |
dynamic |
The expected value for the predicate. |
funcName |
string |
The name of the function to call |
argument name |
type |
defaultValue |
description |
funcName |
string |
N/A |
The name of the function to use for matching. |
args |
mc.types.assocarray |
N/A |
An associative array of arguments to pass to the function. |
expected |
dynamic |
N/A |
The expected value for the predicate. |
method name |
return type |
description |
isMatch |
boolean |
A method that returns a boolean indicating whether the provided item matches the expected value for the predicate. |