Collection.fromCards constructor

Collection.fromCards(
  1. Iterable<Card> cards
)

Creates a new Collection with the given cards.

For each copy of a card, the card is added to the collection. For example, if cards contains two copies of "Darth Vader", then the collection will contain two copies of "Darth Vader".

Implementation

factory Collection.fromCards(Iterable<Card> cards) {
  final map = <CardSet, Map<Card, int>>{};
  for (final card in cards) {
    final cardSet = map.putIfAbsent(card.cardSet, () => {});
    cardSet.update(card, (count) => count + 1, ifAbsent: () => 1);
  }
  return Collection._(map);
}