I think it's better as a library. Also, wow, did I butcher the spelling of niche.
Allen Madsen http://www.allenmadsen.com On Fri, Dec 14, 2018 at 9:31 AM Florian Odronitz <florian.odron...@gmail.com> wrote: > That’s correct, pair_by would be a better name since it forms pairs by the > return value of the match function. > > If it’s too niche for Enum, do you think it fits another module or would > it better be its own library? > > > On 14. Dec 2018, at 15:15, Allen Madsen <allen.c.mad...@gmail.com> > wrote: > > > > I feel like this a bit too nitch for Enum. I'll also say, I was > surprised the implementation sorts the two lists. I think what you've > implemented might better be called something like pair_by. I would have > expected zip_by to allow you to control how the zipped items are combined > in the resulting list. > > > > [ > > [1, 2], > > ~w(one two) > > ] > > |> Enum.zip_by(fn {num, word} -> > > "#{num} is #{word}" > > end) > > #=> ["1 is one", "2 is two"] > > > > This is also what it means in perl: > https://metacpan.org/pod/release/PEVANS/List-UtilsBy-0.09/lib/List/UtilsBy.pm#@vals-=-zip_by-{-ITEMFUNC-}-\@arr0,-\@arr1,-\@arr2,. > .. > > > > However, this could just as easily be handled by: > > > > [ > > [1, 2], > > ~w(one two) > > ] > > |> Enum.zip() > > |> Enum.map(fn {num, word} -> > > "#{num} is #{word}" > > end) > > #=> ["1 is one", "2 is two"] > > > > Allen Madsen > > http://www.allenmadsen.com > > > > > > On Fri, Dec 14, 2018 at 7:19 AM <florian.odron...@gmail.com> wrote: > > Hi, > > > > after having used this functionality in several different projects I > like to propose it to be included in Elixir: > > > > Enum.zip_by/4 is similar to Enum.zip/2 but takes a function which > determines the identity of elements (most often through some kind of > identifier). That means elements can end up having no matching element in > the other list. > > > > It is very handy when doing merges or updates of any kind. I mostly use > it as a preparation step to make on-by-one decisions of how a merge is > handled. > > > > Here is what I put together so far: > > https://github.com/elixir-lang/elixir/compare/master...odo:zip_by > > > > There are some things that I think could be improved where I like to > have some input: > > > > - The code seems a bit bulky, compared to the other functions in the > Enum module (comments could be removed) > > - I don't really like the name of the do_zip_by/3 recursive function > > - Both enumerables have to traversed several times (mapping, sorting, > matching) > > > > Let me know what you think. > > > > Thanks, > > Florian > > > > -- > > 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/e4bfde94-a39f-402c-9487-205dfe59acbf%40googlegroups.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 elixir-lang-core+unsubscr...@googlegroups.com. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3Cu7BEExYRcMSEP1GSqUfg5DCKiZjaf6eY5AH6qpOQgOaA%40mail.gmail.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 elixir-lang-core+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-core/EEF16DFE-864F-40D4-A57B-DD4A05C052E7%40gmail.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 elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3CtuDp3QydTsppHNjatq97sWzn8MjOSdyYg2xErY0cEUxQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.