pytoolz / toolz

A functional standard library for Python.
http://toolz.readthedocs.org/
Other
4.66k stars 259 forks source link

not understanding ***join*** function #514

Closed PyAntony closed 3 years ago

PyAntony commented 3 years ago

Hi,

can someone please explain the following example which is found in the documentation:

def iseven(x):
    return x % 2 == 0
def isodd(x):
    return x % 2 == 1

list(join(iseven, [1, 2, 3, 4], isodd, [7, 8, 9]))

# result: [(2, 7), (4, 7), (1, 8), (3, 8), (2, 9), (4, 9)]

Why iseven, which is supposed to filer the left sequence only, acting on right sequence? And viceversa, isodd, which is supposed to only be filtering the right sequence, is also picking elements from left sequence. This is confusing....

PyAntony commented 3 years ago

Never mind, I got it. You are matching where True == True and where False == False. This should be quickly explained in the documentation though, it is a bit confusing. It seems like the key functions are acting on both sequences each, but this is not the case.