# Introduce a PHP-style \`compact\` function

**URL:** <https://forum.elixirforum.com/t/introduce-a-php-style-compact-function/71308>\
**Category:** Proposals: Ideas\
**Tags:** defmacro\
**Created:** [June 16, 2025, 12:28pm UTC](https://forum.elixirforum.com/t/introduce-a-php-style-compact-function/71308 "2025-06-16T12:28:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MeerKatDev](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/meerkatdev/32/16106_2.png) [@MeerKatDev](https://forum.elixirforum.com/u/MeerKatDev)\
**Post date:** [June 16, 2025, 12:28pm UTC](https://forum.elixirforum.com/t/introduce-a-php-style-compact-function/71308/1 "2025-06-16T12:28:16Z")

</div>

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

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

```

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

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

```

[Link to PHP compact method](https://www.php.net/manual/en/function.compact.php)

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

---

<div class="post-metadata">

**Author:** ![cmo](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmo/32/19618_2.png) [@cmo](https://forum.elixirforum.com/u/cmo)\
**Post date:** [June 16, 2025, 1:17pm UTC](https://forum.elixirforum.com/t/introduce-a-php-style-compact-function/71308/2 "2025-06-16T13:17:48Z")

</div>

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

There are libraries like shorter\_maps, tiny\_maps and others.

---

<div class="post-metadata">

**Author:** ![MeerKatDev](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/meerkatdev/32/16106_2.png) [@MeerKatDev](https://forum.elixirforum.com/u/MeerKatDev)\
**Post date:** [June 16, 2025, 1:23pm UTC](https://forum.elixirforum.com/t/introduce-a-php-style-compact-function/71308/3 "2025-06-16T13:23:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sodapopcan](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sodapopcan/32/34668_2.png) [@sodapopcan](https://forum.elixirforum.com/u/sodapopcan)\
**Post date:** [June 16, 2025, 1:56pm UTC](https://forum.elixirforum.com/t/introduce-a-php-style-compact-function/71308/4 "2025-06-16T13:56:48Z")

</div>

[https://forum.elixirforum.com/t/proposal-add-field-puns-map-shorthand-to-elixir/15452](https://forum.elixirforum.com/t/proposal-add-field-puns-map-shorthand-to-elixir/15452)
