github repository missing flatten() #3

embr opened this Issue Oct 16, 2012 · 4 comments


None yet

2 participants

embr commented Oct 16, 2012

Perhaps I've just missed it, but I can't seem to see any trace of the List.flatten() function in the github repo. It is in the source downloaded form pypi.

phzbox commented Oct 17, 2012

Hi embr, it has been removed in this commit: bc37e58

Reason being that I wanted to keep the library a small as possible and since moka allows any operations on its list, it's easy to flatten it. Maybe since flatten isn't trivial I should consider adding it back.

embr commented Oct 17, 2012

Understandable. I think it would be simple to do if there were some sort of reduce method available (have I just missed that, btw?). But as it stands, I can't see a way to update the entire list through a user defined function. That is, you can change each element in place, but you can't change the whole list in place. Thanks for response.

phzbox commented Oct 18, 2012

Actually, there's the "do" that let you do whatever you want with the list:

>>> x = List([1,2,3]).do(lambda self: List(reversed(self)))
>>> x
[3, 2, 1]

You have to wrap the return object with a call to Moka.List if you plan to continue the chaining however.

That being said I had 'fold' in my todo list so it really was an oversight.

Thanks for bringing it up.

embr commented Oct 18, 2012

I see. I had tried that earlier with the pypi version, but as you may know, that version's do() doesn't store the result of the function back to self but just allows you to add side effects. Thanks for the responses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment