From: Caleb Clausen Date: 2010-04-10T04:02:46+09:00 Subject: Re: Is it possible, a fully general Enumerable#recursive ? On 4/9/10, Intransition wrote: >> Notice: >> >> [1, 2, 3, ['a', 'b', 'c'] ].visit{ |x| x.succ } >> => [2, 3, 4, ["b", "c", "d"]] >> >> But using Enumerator: >> >> [1, 2, 3, ['a', 'b', 'c'] ].visit.map{ |x| x.succ } >> => [2, 3, 4, "b", "c", "d"] >> >> Why is it flattening the result? > > To just make that much stranger: > > [1, 2, 3, ['a', 'b', 'c'] ].visit.with_index{ |x,i| i } > => [0, 1, 2, [3, 4, 5]] > > Doesn't flatten, but somehow the index is being carried on to the > subarray iterations -- that really fracks with my mind. This has got to be a bug. It should at least either flatten or not flatten consistently. > On a side note, I am not so sure that raising an error > is best. Why not just assume that too non-comparable things are equal? Maybe it would help you write a #visit that sorts properly, but in general, I would expect that if I try to sort a collection containing non-comparable objects it's because I made a mistake and put the wrong thing into the collection somehow. So I want to see that error.