# Proc Coercion

`[1, 2, 3].select(&:even?)`
`[1, 2, 3].select { |n| n.even? }`
`is_even = :even?.to_proc=> #<Proc:0x00007ff8cd0c1570(&:even?)>`
`is_even.call(2)=> true`

# Proc Composition

`add_one = -> x { x + 1 }multiply_by_five = -> x { x * 5 }do_both = add_one << multiply_by_fivedo_both.call(6)=> 31[1, 2, 3].map(&do_both)=> [6, 11, 16]`
`[1, 2, 3].map(&add_one << multiply_by_five)=> [6, 11, 16]`

# Closures

`adds = -> x { -> y { x + y } }=> #<Proc:0x00007fca97980df0@(pry):9 (lambda)>adds_one = adds.call(1)=> #<Proc:0x00007fca979f26d0@(pry):9 (lambda)>adds_one.call(2)=> 3`
`[1, 2, 3].map(&adds.call(5))=> [6,7,8]`

# Operators are Methods

`1.+(3)=> 4`
`class Foo  attr_reader :value  def initialize(value)    @value = value  end  def +(other)    self.class.new(other.value + self.value)  endendFoo.new(5) + Foo.new(10)=> #<Foo:0x00007fca978ffe30 @value=15>`

# The Emergence of Mf

`List(1, 2, 3).map(_ + 5)`
`module Mf  def self.+(value)    -> other_value { value + other_value }  endendadd_one = Mf + 1=> #<Proc:0x00007fca979b2800@(pry):52 (lambda)>add_one.call(2)=> 3`
`[1, 2, 3].map(&Mf + 5)=> [6, 7, 8]`
`json_data.map(&Mf['name'])`

# Wrapping Up

--

--

--

## More from Brandon Weaver

Find new posts on dev.to: https://dev.to/baweaver

Love podcasts or audiobooks? Learn on the go with our new app.

## Brandon Weaver

Find new posts on dev.to: https://dev.to/baweaver