zachallaun/mneme

Remove empty raw maps as suggested match patterns

Closed this issue · 2 comments

Proposal

Mneme should no longer generate empty maps as a pattern for maps that contain keys. Note that the behavior for structs would remain the same.

# Maps:
auto_assert %{id: 1, name: "Zach"}
# would NO LONGER SUGGEST
auto_assert %{} <- %{id: 1, name: "Zach"}

# Structs:
auto_assert %User{id: 1, name: "Zach"}
# would still suggest
auto_assert %User{} <- %User{id: 1, name: "Zach"}

Note that if you edited a match to assert an empty map, it would still succeed and be offered as a suggestion when updating. For instance:

auto_assert %{x: 1, y: %{}} <- %{x: 2, y: %{z: 3}}
# would still suggest
auto_assert %{x: 2, y: %{}} <- %{x: 2, y: %{z: 3}}

Context

Two recent issues got me thinking about the utility of suggesting empty maps as patterns: #55, #56.

In my own usage, empty raw maps are rarely useful patterns, whereas empty structs often are, especially when nested.

Request for comment

I'd greatly appreciate any feedback on whether this change would be beneficial/detrimental/neutral to your usage of Mneme. Do you ever use empty raw maps in patterns? Would you miss them?

Big 👍 from me. I don't think that there's any use in a top-level empty map pattern.

Going to move forward with this!