flatten<T> function
- ImmutableList<
ImmutableList< nestedListT> >
Flattens a nested ImmutableList into a single-dimensional ImmutableList.
Given an ImmutableList containing other ImmutableLists as elements, this function will flatten it into a single-dimensional list.
Example:
final nestedList = ImmutableList<ImmutableList<int>>([
ImmutableList<int>([1, 2]),
ImmutableList<int>([3, 4]),
]);
final flatList = flatten<int>(nestedList);
print(flatList); // Outputs: ImmutableList([1, 2, 3, 4])
@param nestedList An ImmutableList of ImmutableLists. @return A flattened ImmutableList.
Implementation
ImmutableList<T> flatten<T>(ImmutableList<ImmutableList<T>> nestedList) {
return flatMap<ImmutableList<T>, T>(identity)(nestedList);
}