Function composition combines small operations into a larger operation.

Composition

composition.rb
suffix = 
trim = ->(text) { text.strip }
upcase = ->(text) { text.upcase }
decorate = ->(text) { "#{text}#{suffix}" }

input = " ruby "
step_one = trim.call(input)
step_two = upcase.call(step_one)
result = decorate.call(step_two)

puts "suffix=#{suffix}"
puts "step_one=#{step_one}"
puts "result=#{result}"
suffix = 
trim = ->(text) { text.strip }
upcase = ->(text) { text.upcase }
decorate = ->(text) { "#{text}#{suffix}" }

input = " ruby "
step_one = trim.call(input)
step_two = upcase.call(step_one)
result = decorate.call(step_two)

puts "suffix=#{suffix}"
puts "step_one=#{step_one}"
puts "result=#{result}"
suffix = 
trim = ->(text) { text.strip }
upcase = ->(text) { text.upcase }
decorate = ->(text) { "#{text}#{suffix}" }

input = " ruby "
step_one = trim.call(input)
step_two = upcase.call(step_one)
result = decorate.call(step_two)

puts "suffix=#{suffix}"
puts "step_one=#{step_one}"
puts "result=#{result}"
composition Composed functions keep each step small while still producing one final result.