Introduce a PHP-style `compact` function

many times we do stuff like (e.g. test setups, json views in phoenix)

aaa = ...
bbb = ...
ccc = ...
%{aaa: aaa, bbb: bbb, ccc: ccc}

and would be cool to have a standard macro doing the same with

compact(aaa, bbb, ccc) # eventually compact_map / compact_keyword

Link to PHP compact method

I’m sorry if this is a duplicate, couldn’t find this in the forum.

Yeah, it has come up previously and IIRC had mixed feedback.

There are libraries like shorter_maps, tiny_maps and others.

any way I could see the discussion? I’m curious

https://elixirforum.com/t/proposal-add-field-puns-map-shorthand-to-elixir/15452

3 Likes