BallotLines<TCandidate extends Comparable>.fromBallots constructor
BallotLines<TCandidate extends Comparable>.fromBallots (
- Iterable<
RankedBallot< ballots, {TCandidate> > - String candidateToText(
- TCandidate
Implementation
factory BallotLines.fromBallots(
Iterable<RankedBallot<TCandidate>> ballots, {
String Function(TCandidate) candidateToText = _defaultCandidateText,
}) {
final grouped = ballots.fold<Map<RankedBallot<TCandidate>, int>>(
<RankedBallot<TCandidate>, int>{},
(map, ballot) {
map[ballot] = (map[ballot] ?? 0) + 1;
return map;
},
);
return BallotLines(
grouped.entries
.map((e) => BallotLine(e.value, e.key.rank))
.toList(growable: false)
..sort(),
candidateToText: candidateToText,
);
}