Andrea Fontana:

Not funny btw :) It's not so easy to find out. And it's not easy to write a "cached map" function if you use classes or some pointers as ElementType...

Not caching _input.front in filter() means that filter() assumes the front() of its argument range to act as a pure function (even if this isn't enforced by the type system). At least this should be documented in std.algorithm ddocs...


Python filter() does not work that way:


from sys import stdout
def fun(x):
    stdout.write("*")
    return x
list(filter(lambda x: True, map(fun, xrange(5))))


Prints:

*****

Bye,
bearophile

Reply via email to