Array Sugar
---------------------
Array Sugar lets you opperate on arrays in much the same way you usually opperate on single objects.
Basic Usage:
[1,2,3,4,5].select < 4 #=> [1,2,3]
([1,2,3,4,5].select < 4) > 2 #=> [3]
(0..10).map / 2.0 #=> [0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0]
Working with trees:
[[1,2],[3,4],[[5]]].map.to_s #=> ["12", "34", "5"]
[[1,2],[3,4],[[5]]].map.leafs.to_s #=> [["1", "2"], ["3", "4"], [["5"]]]
Working with nil:
[1,2,3,nil,4,5].map.to_s #=> undefined method `/' for nil:NilClass
[1,2,3,nil,4,5].map.nils_ok.to_s #=> [0.5, 1.0, 1.5, nil, 2.0, 2.5]
Getting the array back:
[1,2,3].map.to_a #=> [1,2,3] (I know, I know)
Todo:
[[1,2,3]].select.leafs #=> throws right now, this will be fixed in the next version
Install:
gem install arraysugar
hope you enjoy the new, nicer syntax! For feature requests or bug reports, please email me at:
agoric@gmail.com
or add a ticket to the rubyforge tracker :)