How can you assert that a map in a variable matches another map that is a superset?

My gut pick is this one:

subset? =
  fn (map1, map2) ->
    in_other =
      fn {key, value} ->
        {:ok, value} == Map.fetch(map2, key)
      end
    map1
    |> Map.to_list()
    |> Enum.all?(in_other)
  end

as it simply verifies that all the necessary key/value pairs are present and will stop as soon as that is not the case.

In this case I also prefer to use fetch/2 in order the leverage the underlying map functionality rather than relying on in/2’s macro magic even if it makes the code a bit more verbose (so be it).

One thing to be aware of is that the empty set is a subset of any other set - the same is true for empty maps.