#A whole new syntax for intelligently expressing filter, map, or filter_map with built-in caching
Ruby Tracker Feature request page https://bugs.ruby-lang.org/issues/16147
Ruby Gem home https://rubygems.org/gems/ruby_list_comprehension
Summary: List comprehensions are a flexible prototyping tool having iterations in multiple languages. While Ruby is already equipped with powerful enumerable methods, list comprehensions have some unique benefits: [] brackets make array return more intuitive, ruby_list_comprehension automatically determines whether to map, filter, or filter_map(>=2.7.0) which means less syntax to memorize, and beginners or experienced programmers from languages such as Python or Julia, where list comprehensions feature prominently, may find it easier to adapt to Ruby.
(1..10).filter_map{_1 ** 2 if _1 > 5}
(both map and filter so under the hood we use filter_map or map with compact)
[for x in 1..10 do x end]
(exactly the same because no map or filter condition)
(1..10).filter_map{@1**2 if _1 % 2 == 0}
Set.new([1,2,3,4,5]).filter{_1 % 2 == 0}
for x in [1,[1,2,3].reduce{|x,y|x+y}] do x if x end
#(test if parser can distinguish hash {1=>1} from block {|x|x})
$l[[for j in 1..5 do end], for i in 1..5 do end] => [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]
$l[for x in 1..10; x if x % 2 == 0 end]
#(use do
keyword if possible but there is support for semicolons)
(1..10).filter{_1 % 2 == 0}
$l[for x in 1..10 ; x if x % 2 == 0 end]
#(use do
keyword if possible but there is support for semicolons)
(1..10).filter{_1 % 2 == 0}
for x in [1,2,3].reduce{|x,y|x+y}] do x if x end
#(test if parser can distinguish hash {1=>1}
from block {|x|x})