Collection.fromCardSets constructor
Collection.fromCardSets(
- Iterable<
CardSetInventory> cardSets, { - int count() = _defaultCount,
Creates a new Collection containing the cards from each card set.
For each copy of a card, a single card is added to the collection. To
set a different number of copies of a card, provide a count
closure;
note that the number of copies of a card must be greater than zero.
Implementation
factory Collection.fromCardSets(
Iterable<CardSetInventory> cardSets, {
int Function(Card) count = _defaultCount,
}) {
final map = <CardSet, Map<Card, int>>{};
for (final cardSet in cardSets) {
for (final card in cardSet.cards) {
final copies = count(card);
RangeError.checkNotNegative(copies, 'count');
if (copies == 0) {
continue;
}
final cardSetMap = map.putIfAbsent(card.cardSet, () => {});
cardSetMap.update(
card,
(count) => count + copies,
ifAbsent: () => copies,
);
}
}
return Collection._(map);
}