flat ()
Creates a list with all sub-list items from a source list concatenated into it recursively up to a specified depth.
Parameters
$list
- The list to be flattened.
- Type
List
$depth
- The value indicating how deep a nested list structure should be flattened.
- Type
Number
- Default
1
$separator
- The type of separator to be used by the flattened list.
- Type
space | comma | slash | auto
- Default
auto
$bracketed
- Whether the flattened list has square brackets or no brackets.
- Type
Boolean | auto
- Default
false
Return Value
List
- A list with the sub-list items concatenated into it.
Example
@use '@sass-fairy/list';
// 1. Flatten to the default depth
$list: [0, 1, 2, [3, [4]]];
@debug list.flat($list);
// [0, 1, 2, 3, [4]]
// 2. Flatten to a custom depth
$list: [0, 1, 2, [3, 4]];
@debug list.flat($list, 2);
// [0, 1, 2, 3, 4]