orNull<K, V> static method

IMapOfSets<K, V>? orNull<K, V>(
  1. Map<K, Iterable<V>>? map, [
  2. ConfigMapOfSets? config
])

If mapOfSets is null, return null.

Otherwise, create an IMapOfSets from the mapOfSets.

This static factory is useful for implementing a copyWith method that accept regular map of sets. For example:

IMapOfSets<Course, String> studentsPerCourse;

Students copyWith({ Map<Id, Iterable<String>>? studentsPerCourse }) =>
  Students(studentsPerCourse: IMapOfSets.orNull(studentsPerCourse) ?? this.studentsPerCourse);

Of course, if your copyWith accepts an IMapOfSets, this is not necessary:

IMapOfSets<Id, String> studentsPerCourse;

Students copyWith({ IMapOfSets<Id, String>? studentsPerCourse }) =>
  Students(studentsPerCourse: studentsPerCourse ?? this.studentsPerCourse);

Implementation

static IMapOfSets<K, V>? orNull<K, V>(
  Map<K, Iterable<V>>? map, [
  ConfigMapOfSets? config,
]) =>
    (map == null) ? null : IMapOfSets.withConfig(map, config ?? defaultConfig);