123456789101112131415161718192021 |
- #!/usr/bin/ruby
- # https://rosettacode.org/wiki/Functional_Composition
- func compose (f, g) {
- func(n){ f(g(n)) }
- }
- func f(n) {
- n / 64;
- }
- func g(n) {
- n * 32;
- }
- var fg = compose(f, g); # fg(x) is equivalent with: f(g(x))
- assert_eq(fg(4), 2);
- say "** Test passed!";
|