David Alan Black <dblack / candle.superlink.net> wrote:
>
>On Sat, 16 Dec 2000, Ben Tilly wrote:
>
> > David Alan Black <dblack / candle.superlink.net> wrote:
> > >
> > I was talking about your hack to have a map return multiple
> > values, map to anon arrays then flatten.  That hack will
> > not work on all data structures because flatten is
> > recursive.  Your original map_with_indices didn't have
> > that problem.
>
>I'm totally lost now.  As far as I can tell, this example:
>
> > >[1, [], [3,4,[]]] .map do |e| [e.inspect, "hello"]  end .flatten
> > >
> > >  => ["1", "hello", "[]", "hello", "[3, 4, []]", "hello"]
>
>showed that the business of mapping 2-for-one (using the flatten
>"hack") *does* work with multidimensional arrays.  Can you write
>a little example showing a case where things get excessively
>flattened?

When you inspect you flatten the data into a string.  So you have
an array of pairs of strings, and flattening doesn't do anything
surprising.  Try this:

  a = [1, [], [3,4,[]]] .map do |e| [e, "hello"]  end .flatten
  print a.inspect

See the extra flattening now?

[...]
> > Willingness does not equal ability.  I was putting out a guess
> > based on an impression.  The fact that you (with more
> > experience) didn't think my impression was obvious suggests that
> > I am missing something.
>
>Heavens -- I'm not particularly experienced.  I'm a Book Baby (late
>October)  :-)  I'm a bit lost on this part of the thread too.  But
>it's OK.

Heh.

Sorry about not getting right back on this.  Some personal
stuff came up.

Ben
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com