meyercm / shorter_maps

Elixir ~M sigil for map shorthand. `~M{id, name} ~> %{id: id, name: name}`
MIT License
233 stars 11 forks source link

Consider modifieries #3

Closed andrejsm closed 7 years ago

andrejsm commented 7 years ago

Have you considered to use modifiers instead of having lower and upper case sigils? Like Elixir's Sigil_W for example. ShorterMaps could have a and s. Where a stands for atoms (default) and s for strings.

Like this:

~M{a, b, c}
# %{a: a, b: b, c: c}

~M{a, b, c}s
# %{"a" => a, "b" => b, "c" => c}

I'm suggesting this as most of Elixir's sigils, except Sigil_D, Sigil_T and Sigil_N, have lower case sigil to output interpolated and escaped characters.

andrejsm commented 7 years ago

Ahh, never mind, found support for modifiers already exists https://hexdocs.pm/shorter_maps/ShorterMaps.html#sigil_M/2-modifiers. Readme on Github does not list support for modifiers, though.

meyercm commented 7 years ago

Thanks for the careful look; the omission in the README documentation is worth fixing.

Out of curiosity, do you commonly use ~W in some places, and intentionally use ~w in others? If so, what use case causes you to differentiate?

andrejsm commented 7 years ago

I use lower case ~w only, but never had to use interpolation, though.

Did some grepping and found out that mostly I've used ~w with get_in/2:

foo = get_in(bar, ~w(foo bar baz))

With this avoiding to write ["foo", "bar", "baz"].