From: Mike Austin <"mike[nospam]"@...> Date: 2008-12-02T19:44:32+09:00 Subject: Re: Enumerable#select used to return actual values Pe�a wrote: > From: Mike Austin [mailto:"mike[nospam]"@mike-austin.com] > . > # (1..10).select { |a| a * a if a > 5 } > > the difficulty there is that there is no clear separation bw the selection logic and the mapping logic that's... the idea. > # Was it ever there, or did I just have a dream about it? > # It's easy to implement... just wondering. > > it's easy in 1.9.. > > >> p (0..10).select_with_map ->(x){x<5}, ->(x){x*x} > [0, 1, 4, 9, 16] The new syntax looks like a function got run over by a lambda. Twice. I guess it wasn't possible to make them look like lambdas? > one could also do partitioning if 3rd block is provided (wc catches the else portion) > >> p (0..10).select_with_map ->(x){x<5}, ->(x){x*x}, ->(x){x+x} > [[0, 1, 4, 9, 16], [10, 12, 14, 16, 18, 20]] > > > but still i prefer {|x| x<5} over ->(x){x<5} > or maybe, ->{|x| x<5} over ->(x){x<5} I wouldn't mind "&{|x| x < 5}" - shorthand for "&lambda {|x| x < 5}" which you can pass to functions that require a block: (1..10).map &lambda {|n| n * n} Mike