tobgu/pyrsistent

filter/collect support

Closed this issue · 2 comments

I see that the only (apart from immutability) benefit that I get from pvector is transform function. However, transform just changes the elements that satisfy first lambda parameter but do not filter them (so I cannot get rid of the elements I do not need).
To make pyrsistent really useful we need filter method that will filter elements according to conditions. It would also nice to have scala-like collect ( http://allaboutscala.com/tutorials/chapter-8-beginner-tutorial-using-scala-collection-functions/scala-collect-function/ ) method that will filter and then map

tobgu commented

You can use discard to remove elements using transform (https://github.com/tobgu/pyrsistent/blob/master/tests/transform_test.py#L40 for examples). That should pretty much cover the same functionality as filter (albeit inversed), right?

You can also add multiple transformations to the same call to transform. It won't be an exact replica of collect but I think you can achieve the same thing.

If you have a suggestion for a collect like function that you would like to add to pyrsistent I'd be happy to review it!

tobgu commented

Closing this due to lacking response. Please reopen if there are additional information.