Access works like a protocol where you can only extend it for structs.


*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D

On Fri, Jun 17, 2016 at 10:20 PM, OvermindDL1 <[email protected]> wrote:

> Currently I have an Array module modeled on Erlangs for speed with extra
> functions/macros that work like the Dict interface (except mine accepts the
> Array passed in at the beginning or the end of the parameter list since
> Dict has it at the beginning and tuple function calls put it at the end)
> except it only takes integers as keys and hard dies on anything else, but
> is faster than maps (a little less than twice as fast on gets, but
> substantially faster, well over ten times as fast and gets faster the
> larger the data that I am using over maps on erts-7.3/BEAM18, unsure if 19
> is any faster):
> ```elixir
> iex(1)> a = Array.new()
> {Array, 0, 10, nil, 10}
> iex(2)> a = a.resize(400)
> {Array, 400, 1000, nil, 1000}
> iex(3)> a = a.put_new(42, "testing")
> {Array, 400, 1000, nil,
>  {{10, 10, 10, 10, {nil, nil, "testing", nil, nil, nil, nil, nil, nil,
> nil}, 10,
>    10, 10, 10, 10, 10}, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100}}
> ```
>
> How can I also enable this syntax:
> ```elixir
> iex> a[42]
> nil
> ```
>
> Right now it instead raises a `FunctionClauseError` because `Access.fetch`
> is hard-coded to only a couple of things.  Could not something like this be
> added as an `Access.fetch/2` clause so it follows the same pattern as
> maps/structs?
> ```elixir
>   def fetch(tup, key) when is_tuple(tup) and is_atom(elem(tup, 0)) do
>     elem(tup, 0).fetch(tup, key)
>   end
> ```
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-talk" 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-talk/c29cfa0f-513d-4c92-8985-9ebc1ae94548%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-talk/c29cfa0f-513d-4c92-8985-9ebc1ae94548%40googlegroups.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-talk" 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-talk/CAGnRm4KRcmbEJbq%2Bt_OeKP7hVQ6hA%2BvXzY4UoxpU9LKytOWdjg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to