I like Bruce's option a lot and I will proceed with that. Thanks Bruce and everyone!
On Wed, Dec 9, 2020 at 1:48 AM Anil Kulkarni <anil@terminal.space> wrote: > If there was no Enum.with_index/2 function in existence today, how would > we implement it? My personal preference is to do {index, value}, as per > José’s message. > > If we are to make a change, I would prefer to create some new API (for > back-compat), and then deprecate/remove Enum.with_index(). > > > > However, it’s my opinion that this is too much churn for something that is > easily accomplished with `Enum.map()`, and I would just leave it as-is, > chalked up to legacy decisions. > > > > -Anil > > > > *From: *<elixir-lang-core@googlegroups.com> on behalf of Adam Lancaster < > a...@a-corp.co.uk> > *Reply-To: *"elixir-lang-core@googlegroups.com" < > elixir-lang-core@googlegroups.com> > *Date: *Tuesday, December 8, 2020 at 4:29 PM > *To: *"elixir-lang-core@googlegroups.com" < > elixir-lang-core@googlegroups.com> > *Subject: *Re: [elixir-core:9842] Enum.index/2 > > > > You could also use the new zip_with: > > > > Map.new(Enum.zip_with(list, 0..length(list), & {&2, &1})) > > > > On Tue, 8 Dec 2020 at 23:51, Christopher Keele <christheke...@gmail.com> > wrote: > > I think that even if it enabled awesome optimization opportunities, > 1. Having both *Enum.index_with* and *Enum.index*/*indexed* will confuse > people. > > 2. Straying from Elixir's consistent API design of "Module X functions > take X's as their first argument" will confuse people. > > a. Especially in the very consistent and large-surface-area *Enum* > module. > > > > Both together seem like a less-than-ideal combination. These trade-offs > may be worth it depending on what is gained, though. > > > > I hadn't seen the second point mentioned yet in this thread yet. Which > makes me wonder if there is a *different* module it might belong under, > instead, resolving both problems while preserving the intention-revealing > *index* function name? > > > > ie: *Integer.index(start \\ 0 :: non_neg_integer, Enum.t) :: Enum.t* > > Kind of communicates that we are indexing an enumerable by an integer > value; and just appears a little non-standard when we omit the starting > point. > > > > Creating a new module namespace for such a function to live--ex *Index*--seems > a little excessive in this case, a costly increase in the surface of the > standard library. (Is *Enum.Index.by/2 <http://Enum.Index.by/2>* unreasonable? > Probably.) > > Worth nothing that these sorts of one-off-function discussions are exactly > how some modules we have today came into being, though--*Atom* and *Tuple* > come > to mind. But "indexes" are hardly first-class language concepts. > > On Tuesday, December 8, 2020 at 2:02:13 PM UTC-8 br...@grox.io wrote: > > There is a bit of a collision with the option for the offset, but you > could pattern match that. > > > > -bt > > > > On Tue, Dec 8, 2020 at 4:57 PM Zach Daniel <zachary....@gmail.com> wrote: > > I like that idea a lot Bruce. Let’s you do something like: > > > > maps |> Enum.with_index(&Map.put(&1, :index, &2)) > > > > On Tue, Dec 8, 2020 at 4:50 PM Bruce Tate <br...@grox.io> wrote: > > Maybe a transform function on with_index? > > > > Enum.with_index([:a, :b, :c], &{&2, &1}) > > > > -bt > > > > On Tue, Dec 8, 2020 at 3:05 PM José Valim <jose....@dashbit.co> wrote: > > I would like to propose an Enum.index/2 function. It behaves like > with_index/2 but the index is the first argument: > > > > iex> Enum.index([:a, :b, :c]) > [{0, :a}, {1, :b}, {2, :c}] > > > > I am hoping it reads "index" this tuple (hence the index as the first > element. While with_index means attach an index information to each element > (hence the second element). Is this sound? > > > > Thank you, > > > > -- > 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/CAGnRm4K6h7c1UbiEfoEsyCXGJRbO8he%3DFJ84yxC%2B3-GOo-2MwQ%40mail.gmail.com > <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4K6h7c1UbiEfoEsyCXGJRbO8he%3DFJ84yxC%2B3-GOo-2MwQ%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > > > > -- > > > > Regards, > > Bruce Tate > > CEO > > > > [image: Image removed by sender.] > > > > Groxio, LLC. > > 512.799.9366 <(512)%20799-9366> > > br...@grox.io > > grox.io > > -- > 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/CAFXvW-4QOLzA4h34KBVSF1OnMFzxJZEwReV334YP3Pwu7cYX1g%40mail.gmail.com > <https://groups.google.com/d/msgid/elixir-lang-core/CAFXvW-4QOLzA4h34KBVSF1OnMFzxJZEwReV334YP3Pwu7cYX1g%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-co...@googlegroups.com. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-core/CAK-yb0AY9GhKiZJ9GS78%2BW3z5m3%3Ds-F%2BNrQiUYje2WOT%3D65ScA%40mail.gmail.com > <https://groups.google.com/d/msgid/elixir-lang-core/CAK-yb0AY9GhKiZJ9GS78%2BW3z5m3%3Ds-F%2BNrQiUYje2WOT%3D65ScA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > > > > -- > > > > Regards, > > Bruce Tate > > CEO > > > > [image: Image removed by sender.] > > > > Groxio, LLC. > > 512.799.9366 <(512)%20799-9366> > > br...@grox.io > > grox.io > > -- > 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/8cfe7aca-a579-405e-89a7-3f81774af255n%40googlegroups.com > <https://groups.google.com/d/msgid/elixir-lang-core/8cfe7aca-a579-405e-89a7-3f81774af255n%40googlegroups.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/CADwgC_C0nMQU894350s94OoVfymHFGyJnXYpgwR%3DmUvMDqsmhg%40mail.gmail.com > <https://groups.google.com/d/msgid/elixir-lang-core/CADwgC_C0nMQU894350s94OoVfymHFGyJnXYpgwR%3DmUvMDqsmhg%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/0100017644f82b24-a6e1b307-78f1-4b83-8d2e-99c40f663533-000000%40email.amazonses.com > <https://groups.google.com/d/msgid/elixir-lang-core/0100017644f82b24-a6e1b307-78f1-4b83-8d2e-99c40f663533-000000%40email.amazonses.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/CAGnRm4%2BUzYgQExrZzxbSOedbXCwUhogD9uCu4PY0PeYNwM4caw%40mail.gmail.com.