The input size is an enumerable and it is not guaranteed we can retrieve its size in constant time. The most common input is a list and it would require at least traversing the list one more time.
Right, for Map.new/1, you’d have to traverse it one more time. But for Map.new/2, isn’t the enumerable reduced into a list before generating the map? I was thinking that the reduction could count the list at the same time, requiring no extra traversals. Regardless, thanks for explaining your reasoning! Myron On Wed, Oct 4, 2017 at 8:45 AM, José Valim <[email protected]> wrote: > > José, would you be open to the addition of a Map.new!/2 function that >> raises an error when there are duplicate keys? Although, maybe that implies >> that Map.new/2 returns {:ok, map} (which is obviously doesn’t). >> > I am not convinced this is an extremely common use case to justify its > addition to the standard library. Especially one that can be implemented in > few lines of code. > >> I was hoping we could at least detect this situation (but not >> necessarily detect what the duplicate keys are) in constant time by using >> map_size/1 on the resulting map, and comparing it to the input size. >> > The input size is an enumerable and it is not guaranteed we can retrieve > its size in constant time. The most common input is a list and it would > require at least traversing the list one more time. > > > -- > You received this message because you are subscribed to a topic in the > Google Groups "elixir-lang-core" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/elixir-lang-core/EessBQaaBsE/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/elixir-lang-core/CAGnRm4%2B6__DcCdEpArNQPMyVri3HYKe%2BTw% > 2BT3kUxuY5sRrDSSg%40mail.gmail.com > <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2B6__DcCdEpArNQPMyVri3HYKe%2BTw%2BT3kUxuY5sRrDSSg%40mail.gmail.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-core" 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-core/CADUxQmuNO194aO-LDz-EZMBRcfAPAEMGukY4RkM2Ds%2BiEDghDg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
