removeDuplicates<T> function

Parser<T> removeDuplicates<T>(
  1. Parser<T> parser
)

Returns a copy of parser with all duplicates parsers collapsed.

Implementation

Parser<T> removeDuplicates<T>(Parser<T> parser) {
  final uniques = <Parser>{};
  return transformParser(parser, <R>(source) {
    return uniques.firstWhere((each) {
      return source != each && source.isEqualTo(each);
    }, orElse: () {
      uniques.add(source);
      return source;
    }) as Parser<R>;
  });
}