Last active
December 30, 2015 15:09
-
-
Save v6ak/7846195 to your computer and use it in GitHub Desktop.
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
| createPlusN n x = x+n | |
| f = createPlusN 2 | |
| g = createPlusN 5 | |
| main = putStrLn $ show (f(g 6)) |
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
| interface Function1<P1, R>{ | |
| R apply(P1 p1); | |
| } | |
| public class plusn{ // Java naming conventons ignored to allow plusn.<programming language suffix> convention. | |
| static Function1<Integer, Integer> createPlusN(final Integer n){ | |
| return new Function1<Integer, Integer>(){ | |
| public Integer apply(Integer x){ | |
| return x+n; | |
| } | |
| }; | |
| }; | |
| public static void main(String...args){ | |
| Function1<Integer, Integer> f = createPlusN(2); | |
| Function1<Integer, Integer> g = createPlusN(5); | |
| System.out.println(f.apply(g.apply(6))); | |
| } | |
| } |
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
| function createPlusN(n){ | |
| return function (x){ | |
| return x+n; | |
| }; | |
| }; | |
| var f = createPlusN(2); | |
| var g = createPlusN(5); | |
| console.log(f(g(6))); |
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
| <?php | |
| function createPlusN($n){ | |
| return function ($x) use($n){ | |
| return $x+$n; | |
| }; | |
| }; | |
| $f = createPlusN(2); | |
| $g = createPlusN(5); | |
| echo $f($g(6)); |
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
| def createPlusN(n: Int) = | |
| (x: Int) => x+n | |
| val f = createPlusN(2) | |
| val g = createPlusN(5) | |
| println(f(g(6))) |
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
| #!/bin/bash | |
| # Rather for fun | |
| function createPlusN { | |
| local n=$1 | |
| local f="/tmp/plus-$n" | |
| (echo "#!/bin/bash"; echo "echo \$((\$1+$n))") > "$f" | |
| chmod +x "$f" | |
| echo "$f" | |
| } | |
| f=$(createPlusN 2) | |
| g=$(createPlusN 5) | |
| echo $($f $($g 6)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment