Last active
April 7, 2019 06:24
-
-
Save asifmom/64d172899f6ee24bfbc02a2a6fe4df86 to your computer and use it in GitHub Desktop.
scala and ruby composer example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Scala Example | |
def composer[A,B,C](f1:B=>C,f2:A=>B):A=>C={ | |
(n:A)=>f1(f2(n)) | |
} | |
def mul3(n:Int)={n*3} | |
def add1(n:Int)={n+1} | |
composer(mul3,add1)(2) | |
// Ruby Example | |
make_adder = ->(x){ | |
->(n) {n+x} | |
} | |
compose= ->(f,g){ | |
->(n){f.(g.(n))} | |
} | |
add1=make_adder.(1) | |
add1.(2) | |
mul3 = ->(n){n*3} | |
compose.(mul3,add1).(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment