You now have a good understanding of iterators and closures and how they can be used to process collections of data.
In this challenge, you will use iterators to filter out duplicate items from a collection of potentially redundant entries.
Define a function that takes a collection of items (as an iterator) and returns a collection of unique items in sorted order. The items are represented as strings. You are expected to handle duplicates and ignore entries that are empty or consist solely of whitespace.
Your function signature and return types must be determined by you, but the input must implement the Iterator
trait, ensuring flexibility for different iterator sources.
String
, &String
, or &str
items.HashSet
to track unique items.filter_map
method to remove invalid entries (e.g., empty or whitespace-only strings).trim
method on strings to handle whitespace effectively.HashSet
provides a method inesert
that returns a bool
indicating whether the item was already present.Vec
and call the sort
method.