filter ()
Creates a list of all the items from a source list that satisfy the test implemented by the specified function.
Parameters
$list
- The list from which items will be tested.
- Type
List
$predicate
- The function that tests each item for a condition. The first parameter is the current item being processed in the list. The second parameter is the index of the current item being processed in the list. The third parameter is the list being processed. The returned value will be compared for truthiness.
- Type
Function
$args
- Additional parameters which are provided to predicate function.
- Type
ArgList<*>
- Default
()
$separator
- The type of separator to be used by the extracted list. Must be passed by name.
- Type
space | comma | slash | auto
- Default
auto
Return Value
List
- A list with the items that pass the test provided by the predicate function; otherwise, an empty list.
Example
@use 'sass:meta';
@use '@sass-fairy/list';
@function _greater-than-fifty($item, $void...) {
@return $item > 50;
}
$list: 32 8 65 79 34 8 13 66 18;
@debug list.filter($list, meta.get-function('_greater-than-fifty'));
// 65 79 66