kachayev / fn.py

Functional programming in Python: implementation of missing features to enjoy FP
Other
3.35k stars 204 forks source link

Recursion error with flatten and unicodes #73

Open gabrielpjordao opened 9 years ago

gabrielpjordao commented 9 years ago

Hey, I get recursion errors on Python 2.7 while executing the following code:

list(flatten([ ['a', u'c'], ['a', 'b'] ]))

I think the issue is here (https://github.com/kachayev/fn.py/blob/master/fn/iters.py#L224), but as I couldn't take a deeper look at it yet, I'm just creating the issue to let you guys know.

microamp commented 9 years ago

Looks like the current implementation would only work in Python 3.

The unicode in u'c' is causing the issue in your case since unicode and str are two different things in Python 2. There is basestring from which both of these inherit, but using that would only work in Python 2 again.