Bug in Iter.chain

2 views
Skip to first unread message

Imri Goldberg

unread,
Apr 1, 2010, 10:17:16 AM4/1/10
to MochiKit
Here is a firebug log to show the bug, present in mochikit 1.4.2, and according to a test I did, also in mochikit 1.5:

>>> list([1])
[1]
>>> list(chain([1],[2]))
[1, 2]
>>> list(chain([1],[2],[3]))
[1, 2, 3]
>>> list(chain([],[],[3]))
[]

>>> list(chain([1],[2],[3]))
[1, 2, 3]
>>> list(chain([],[2],[3]))
[2, 3]
>>> list(chain([],[],[3]))
[]

>>> list(chain([],[],[1]))
[]
>>> list(chain([1],[],[1]))
[1]
>>> list(chain([1,2],[],[1]))
[1, 2]



To fix the bug, I suggest changing lines 298-300 (in 1.4.2) of next (defined in chain()) from:
                        argiter.shift();
                        var result = argiter[0].next();
                        return result;
to:
                        argiter.shift();
                        continue;

Cheers,
Imri

--
Imri Goldberg
--------------------------------------
http://plnnr.com/ - automatic trip planning
http://www.algorithm.co.il/blogs/
--------------------------------------
-- insert signature here ----
Reply all
Reply to author
Forward
0 new messages