One option that already exists:

[
  config,
  config_host,
  config_user,
  config_port
]
|> Enum.reduce(&Keyword.merge/2)

Allen Madsen
http://www.allenmadsen.com


On Tue, Apr 4, 2023 at 4:53 PM Austin Ziegler <halosta...@gmail.com> wrote:

> I recently found myself wanting a variadic version of `Keyword.merge/2`
> similar to the way that Ruby’s `Hash#merge` works. Would
> `Keyword.merge_all/1` and `Map.merge_all/1` make sense?
>
> You could go from this:
>
> ```elixir
>   config
>   |> Keyword.merge(config_host)
>   |> Keyword.merge(config_user)
>   |> Keyword.merge(config_port)
> ```
>
> to this:
>
> ```elixir
> Keyword.merge_all([
>   config,
>   config_host,
>   config_user,
>   config_port
> ])
> ```
>
> I’d be happy to work on a PR to do this if there‘s interest.
>
> -a
> --
> Austin Ziegler • halosta...@gmail.com • aus...@halostatue.ca
> http://www.halostatue.ca/http://twitter.com/halostatue
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elixir-lang-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/CAJ4ekQtoLaW%3D7wkYLcjLnUSwR2F97oTwCMUSkoBiiKLfhKn9ow%40mail.gmail.com
> <https://groups.google.com/d/msgid/elixir-lang-core/CAJ4ekQtoLaW%3D7wkYLcjLnUSwR2F97oTwCMUSkoBiiKLfhKn9ow%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3Ct-xsRieRuhbHwkkoqu4%3DjMevX1tz83WYZP%2BY4TT%3DTMbA%40mail.gmail.com.

Reply via email to