Procs and Lambdas • Exercise 4/4

Compose Functions

00:00
0
25 points

Instructions

Create a function compose that takes two procs (f and g) and
returns a new proc that applies g first, then f.

Mathematical composition: (f ∘ g)(x) = f(g(x))

Example:
```ruby
add_one = ->(x) { x + 1 }
double = ->(x) { x * 2 }

composed = compose(add_one, double)
composed.call(3) # double(3) = 6, add_one(6) = 7

=> 7

Your Code

Results

Click "Run Tests" to see results