Created
March 20, 2015 08:01
-
-
Save wookay/25430088033973b2b2df to your computer and use it in GitHub Desktop.
unary-function-chainer.jl
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
# http://www.codewars.com/kata/unary-function-chainer | |
# http://stackoverflow.com/questions/28713934/how-to-implement-unary-function-chainer-using-python | |
f1 = (x) -> x*2 | |
f2 = (x) -> x+2 | |
f3 = (x) -> x^2 | |
chained(funcs) = reduce((f,g)->(n)->n|>f|>g, funcs) | |
@assert 4 == chained([f1 f2 f3])(0) | |
@assert 36 == chained([f1 f2 f3])(2) | |
@assert 12 == chained([f3 f2 f1])(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment