A list of maps actually …
There is a Enum.min_by/3 but that returns only a single value. But all these functions are linked to the source so you can find out how that works - it turns out that it is based on - Lists.foldl/3 - a function you can use to solve your problem (or Enum.reduce/3).
Now both reduce and foldl work on an accumulator value - my choice would be a tuple like (min_value, [maps_with_min_value]). So every time a new element of the list is inspected a decision has to be made:
- Is this lower than
min_value? If yes, start a new list for the new min value resulting in a tuple(new_min_value, [map_with_new_min_value]) - Is this equal to
min_value? If yes, add the new map to the list, i.e.(min_value,[new_map| others]) - Otherwise leave the tuple unchanged.
Note also that you should also account for being handed an empty list - i.e. there is no minimum - then the resulting list should simply be empty. But if there are any maps to process in the list you simply take the first map as your initial minimum for the accumulator and process the remainder of the list with foldl or reduce.
PS: With pattern matching you can just use the list as an accumulator (i.e. peek inside the first element of the list rather than holding min_value separately).


















