[proposal] Nested Map.from_struct/1

45 views
Skip to first unread message

Weslei Juan Novaes Pereira

unread,
Sep 27, 2023, 4:40:04 PM9/27/23
to elixir-lang-core
The current Map.from_struct/1 works only in the first level of a struct. It would be great if it's possible to handle nested structs without writing helpers. Maybe the default behavior would keep the same, but just add an option to recursively converts the struct, like
`Map.from_struct(instance, nested: true)` or something like this.

José Valim

unread,
Sep 27, 2023, 4:52:45 PM9/27/23
to elixir-l...@googlegroups.com
This is a small function that can be part of your application or a package, we do not plan to add it to the standard library at the moment. Thank you. :)

On Wed, Sep 27, 2023 at 10:40 PM Weslei Juan Novaes Pereira <wesl...@gmail.com> wrote:
The current Map.from_struct/1 works only in the first level of a struct. It would be great if it's possible to handle nested structs without writing helpers. Maybe the default behavior would keep the same, but just add an option to recursively converts the struct, like
`Map.from_struct(instance, nested: true)` or something like this.

--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/4f2ac48a-e80a-4b0e-a368-e8638fb433b9n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages