compact method
Creates an list of elements where the values of the list are not Falsey
.
Avoid calling it on fixed-length list.
//It alters the list object if the list is not fixed-length list.
var list = ['a', null, '', false, 'b'];
var compactedData = list.compact(); // ['a', 'b'];
//It returns new Object of compacted data;
var list = ['a', null, '', false, 'b'];
//here the list object is not altered
var compactedData_new_object = compact(list); // ['a', 'b'];
Implementation
List<T?>? compact() {
removeWhere((element) => isFalsey(element));
return this;
}