meyercm / shorter_maps

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

Support for struct update ? #5

Closed niahoo closed 7 years ago

niahoo commented 7 years ago

Hi ?

Would it be feasible to have support for struct updates : ~M(%State state|val1, val2) ?

meyercm commented 7 years ago

Thanks for your interest in the project! Currently, ShorterMaps works on Structs because they are maps, e.g.: ~M{state|val1, val2}, which expands to %{state|val1: val1, val2: val2}. By adding the syntax you propose, you'd gain compile-time checking of keys.

I think this is definitely syntax we can and should support, though at the current moment my time is a bit stretched. I'll definitely add this with my next update, but if you are looking to use it right away, I'll gladly welcome a pull request.

Chris

niahoo commented 7 years ago

Sure I would like to help, but I'm not sure I could know how to do that. I'll give it a try, though :)

meyercm commented 7 years ago

I've published version 2.2, which provides this functionality. Please comment after you've given it a try to let me know if it solves your need.

niahoo commented 7 years ago

Hey, thank you, it works great !