As a protocol it would be considered to have no tuple implementation though, of which I could then supply. However it appears it is not a protocol in the slightest and it is instead pure function matching with the compiler doing magic to turn `a[1]` into `Access.fetch(a, 1)`, thus one more overload would be wonderfully helpful. :-)
On Friday, June 17, 2016 at 2:24:08 PM UTC-6, José Valim wrote: > > 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] > <javascript:>> 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] <javascript:>. >> 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/79a1ab8f-1407-4bf3-9843-8722a6463edb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
