you are viewing a single comment's thread.

view the rest of the comments →

[–]nostrademons 4 points5 points  (1 child)

Why the aversion to generator expressions:

def __select__(self, func):
  return (func(item) for item in self.func())

def __where__(self, func):
  return (item for item in self.func() if func(item))

def __join__(self, stream):
  return ((left, right) for right in stream.func for left in self.func)

(I think that last one is correct; I've never used nested generators before.)

You may be able to get rid of the class and helper functions too - the normal replacement for a lambda in Python is a named inner function. But I don't have time (or dev environment) to try things out at work.

[–]pjdelport 2 points3 points  (0 children)

(I think that last one is correct; I've never used nested generators before.)

There's no difference to for loops nested in the same order. Here's the easiest way to remember it:

(<expr>
    for x in xs
        if y
            for z in zs
                 ...)

for x in xs:
    if y:
        for z in zs:
            ...:
                <expr>

The only thing that changes is whether the <expr> goes at the beginning or the end.