traverse<A extends Object, B extends Object> function
Maps over the list and applies f
to each non-null element.
Returns the list of non-null values if all elements and results of
applying f
are not null, otherwise returns null.
Implementation
List<B>? traverse<A extends Object, B extends Object>(
List<A?> xa,
Func1<A, B?> f,
) {
final List<B> result = [];
for (final a in xa) {
if (a == null) return null;
final b = f(a);
if (b == null) return null;
result.add(b);
}
return result;
}