Ah, I see why you are confused. You did not read the full question.
Near the bottom of the post:
There was confusion about this on the linked post. I later clarified:
Part of the problem was the post was moved and merged into some other post which had nothing to do with my proposal and was a discussion on documentation.
To clarify the point so that everyone can understand:
- My original proposal was to add a version of
mapwhich works with binary operators.map_binaryor some other name. - Please don’t misunderstand:
mapworks with binary operators if you provide two iterables. This is not the same problem. I am proposing something which takes a single iterable. - I suggested this as an intermediate step to solving the
all_equalproblem. - The current suggestions to implement
all_equalare either slow, or they use some form of prematurely optimized “hack” resulting in unreadable code. (The point of Python is it is supposed to be less complicated than something like C++, not more.) - I suggested adding this because it is more general than implementing
all_equaldirectly. - However it comes with disadvantages: One is that although
binary_mapis obvious, it cannot be extended further in an obvious way. How would you implement a version for a function of three arguments? It isn’t clear how they should align over the input elements from the iterable. Should you advance the iterable by 1 step each time or 2? In the first case you have something which overlaps elements twice, in the second case you only overlap a single element. The fact that this is complicated to explain perhaps suggests the idea is already too complicated. It’s also not obvious what other usecases you might have. For example, if you want to add all elements withoperator.addthere is already asumfunction. Similarly, there is a product function which you could also implement withbinary_mapplusoperator.mul. Then for other binary operators, it’s not clear what the result of mappingoperator.suboroperator.divmight be? Hopefully it’s clear what I’m describing here, but I suspect it isn’t. The fact that it is much easier to explain with a diagram suggests that this is probably not a good idea. - I then went away to attempt to implement such
all_equaldirectly, withoutmap_binary. I did this because it became obvious to me thatall_equalwould be easier to implement directly instead. - The difference in performance is a factor of 2 for iterables containing objects which have simple implementations of
__eq__. - It makes no difference on a list of 1 strings where the length of the string is infinite, because most of the runtime is spent evaluating
__eq__and not in the iterating part.