No the stdlib does not have that and you’ll see exactly why: it’s easy to do it yourself.
%{"z" => 4, "y" => 6, "x" => 7}
|> Map.take(["x", "y"]) # only take keys "x" and "y"
|> Map.to_list() # convert the map to a list of tuples
|> Enum.sort_by(fn {key, _value} -> key end) # sort the list of tuples by their first element
And you will get [{"x", 7}, {"y", 6}] as your result.
That’s super inefficient though. If you had e.g. a map with 20 elements and wanted 10 of them, that solution in SO would do 10 map lookups.
Saving a line or two of code just to make the complexity of the code something almost O(n^2) is a bad practice. Whereas the Map.take + Enum.sort_by is not even two full passes of the underlying list.
sort_by/3 calculates the comparison value for each element in the enumerable once instead of once for each element in each comparison. This implies sort_by/3 must do an initial pass on the data to compute those values.
However, if those values are cheap to compute, for example, you have already extracted the field you want to sort by into a tuple, then those extra passes become overhead. In such cases, consider using List.keysort/3 instead