EntilZha / PyFunctional

Python library for creating data pipelines with chain functional programming
http://pyfunctional.pedro.ai
MIT License
2.41k stars 132 forks source link

Reverse fails on sequences #136

Closed simlei closed 6 years ago

simlei commented 6 years ago

Pretty simple bug, excuse me for not detailing it perfectly, but this should be reproduced in no time:

import functional as f
f.seq(1,2,3).map(lambda x: x+1).reverse()

yields

/xxx/.local/lib/python2.7/site-packages/functional/execution.pyc in evaluate(self, sequence, transformations)
     29                 result = transform.function(list(result))
     30             else:
---> 31                 result = transform.function(result)
     32         return iter(result)
     33 

TypeError: argument to reversed() must be a sequence

The engine tries to reverse an imap iterable, basically.

simlei commented 6 years ago

If you'd want to look at a possible solution, I have made a PR to fix it for now. Excuse the fast move, I have not researched any Contributing guidelines, but I am a bit in a hurry. This would be make reversion a PRE_COMPUTE strategy transformation. I should be happy if that is the only transformation that fails but somehow I doubt it.

cf. https://github.com/EntilZha/PyFunctional/pull/137

EntilZha commented 6 years ago

Closing since PR was merged and unit test was modified to test for this. Thanks for the bug report.