(proc)
blocks and lambda expressions
clojure
(proc)Matching:
- brace blocks, e.g.
{ |x| x } - do/end blocks, e.g.
do |x| x end - lambda expressions, e.g.
->(x) { x }
Behavior
- Matches blocks and lambdas; does not match
Proc.newcalls.
Examples
Audit all blocks and lambdas before refactoring iteration patterns.
clojure
(proc)Selects in lines { 1, 0, 5 } but not in { }:
ruby
items.each { |x| x + 1 }
items.map do |x|
x * 2
end
transform = ->(x) { x + 1 }Find lambdas used as callbacks.
clojure
(:and (proc) (:text /->/))Selects in lines { 1 } but not in { 2 }:
ruby
handler = ->(x) { x + 1 }
items.each { |x| x + 1 }