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* 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 >>> >>> >>> <https://bowtie.mailbutler.io/tracking/hit/f8218219-d2a8-4de4-9fef-1cdde6e723f6/c7c97460-016e-45fb-a4ab-0a70318c7b97> >>> >>> 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 > > > <https://bowtie.mailbutler.io/tracking/hit/f8218219-d2a8-4de4-9fef-1cdde6e723f6/c7c97460-016e-45fb-a4ab-0a70318c7b97> > > 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.