Elixir could define Access.keys/1, which would work like the following:

Access.keys([:foo, bar]) == [Access.key(:foo), Access.key(bar)]

For defaults, you would use a tuple of key and default.

Access.keys([{:foo, %{}}, bar]) == [Access.key(:foo, %{}), Access.key(bar)]


Allen Madsen
http://www.allenmadsen.com

On Thu, Dec 8, 2016 at 9:49 AM, José Valim <[email protected]>
wrote:

> The above wouldn't be desired because you lose the important property of
> asserting the field is there. Plus, implementing behaviour means defining
> three functions, and I don't believe defstruct should pollute the user
> module with functions more than necessary.
>
> One of the reasons Access was moved to a Behaviour from a Protocol was
> exactly to promote proper usage with structs.
>
>
>
> *José Valim*
> www.plataformatec.com.br
> Skype: jv.ptec
> Founder and Director of R&D
>
> On Thu, Dec 8, 2016 at 3:08 PM, Allen Madsen <[email protected]>
> wrote:
>
>> Would it be acceptable and sufficient, when using the defstruct macro,
>> to define default implementations of the methods required for the Access
>> behaviour?
>>
>> Allen Madsen
>> http://www.allenmadsen.com
>>
>> On Thu, Dec 8, 2016 at 5:20 AM, Ólafur Arason <[email protected]>
>> wrote:
>>
>>> What is the exact problem I don't get it from the description is it that
>>> struts don't have Access built in, because that is solveable, or that
>>> because you have default value like nil set in a struct you can't create a
>>> nested structure on the fly?
>>>
>>> Regards,
>>> Olaf
>>>
>>> --
>>> 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 [email protected].
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/elixir-lang-core/1f0a4e4c-83a6-4329-9e02-771369f2793a%40
>>> googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> 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 [email protected].
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/elixir-lang-core/CAK-y3Cs_oUXWvKp2_3cHEw2ErYUOJg65RsFt8y
>> Yg%3DVp%2BEqCNpg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3Cs_oUXWvKp2_3cHEw2ErYUOJg65RsFt8yYg%3DVp%2BEqCNpg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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 [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/elixir-lang-core/CAGnRm4JsQ_2vMC5tvKJR6K8iePUJB2tPX_
> 7OvxHEQ6TT7hp%2B-g%40mail.gmail.com
> <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4JsQ_2vMC5tvKJR6K8iePUJB2tPX_7OvxHEQ6TT7hp%2B-g%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3Cv4tXmtCeXWedFUju2QbMzmzVJy8TshXDMJxXbyCzaYkw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to