orNull<T> static method
If Iterable is null
, return null
.
Otherwise, create an IList from the Iterable. Fast, if the Iterable is another IList.
This static factory is useful for implementing a copyWith
method
that accepts an Iterable. For example:
IList<String> names;
Students copyWith({Iterable<String>? names}) =>
Students(names: IList.orNull(names) ?? this.names);
Of course, if your copyWith
accepts an IList, this is not necessary:
IList<String> names;
Students copyWith({IList<String>? names}) =>
Students(names: names ?? this.names);
Implementation
static IList<T>? orNull<T>(
Iterable<T>? iterable, [
ConfigList? config,
]) =>
(iterable == null) ? null : IList.withConfig(iterable, config ?? defaultConfig);