orNull<K, V> static method
If Map is null
, return null
.
Otherwise, create an IMap from the Map.
This static factory is useful for implementing a copyWith
method
that accepts maps. For example:
IMap<Id, String> studentsPerId;
Students copyWith({Map<Id, String>? studentsPerId}) =>
Students(studentsPerId: IMap.orNull(studentsPerId) ?? this.studentsPerId);
Of course, if your copyWith
accepts an IMap, this is not necessary:
IMap<Id, String> studentsPerId;
Students copyWith({IMap<Id, String>? studentsPerId}) =>
Students(studentsPerId: studentsPerId ?? this.studentsPerId);
Implementation
static IMap<K, V>? orNull<K, V>(
Map<K, V>? map, [
ConfigMap? config,
]) =>
(map == null) ? null : IMap.withConfig(map, config ?? defaultConfig);