From: Yusuke ENDOH Date: 2009-10-25T11:04:05+09:00 Subject: [ruby-core:26287] Re: New Enumerable#flat_map Hi, 2009/10/25 Marc-Andre Lafortune : > I noticed the new Enumerable#flat_map (aka collect_concat) and I was > wondering what prompted the creation of this method. > > I'm probably missing something, but what is the difference between: > enum.collect_concat(&block) > and > enum.map(&block).flatten(1) > ? > > In what kind of circumstances is flat_map needed? I guess the rationale: - map+flatten(1) is a bit too long in spite of a frequent idiom. - flat_map is shorter and plainer than map+flatten(1). - flat_map does not create intermediate array. - flat_map is provided in Scala (and Haskell). [direct reason?] http://twitter.com/yukihiro_matz/statuses/5108220843 Thanks, -- Yusuke ENDOH