group method
Groups all slots by their weekday and time unit.
Implementation
Map<Weekday, Map<(SlotTimeUnit, SlotTimeUnit), List<Slot>>> group() {
if (!state.hasData) {
return {};
}
final grouped = <Weekday, SplayTreeMap<(SlotTimeUnit, SlotTimeUnit), List<Slot>>>{};
for (final slot in state.requireData) {
grouped[slot.weekday] ??= SplayTreeMap((a, b) {
if (a.$1 == b.$1) {
return a.$2.compareTo(b.$2);
}
return a.$1.compareTo(b.$1);
});
final timeGroup = (slot.startUnit, slot.endUnit);
grouped[slot.weekday]![timeGroup] ??= [];
grouped[slot.weekday]![timeGroup]!.add(slot);
}
return grouped;
}