Skip to content

Instantly share code, notes, and snippets.

@v6ak
Last active December 30, 2015 15:09
Show Gist options
  • Select an option

  • Save v6ak/7846195 to your computer and use it in GitHub Desktop.

Select an option

Save v6ak/7846195 to your computer and use it in GitHub Desktop.
createPlusN n x = x+n
f = createPlusN 2
g = createPlusN 5
main = putStrLn $ show (f(g 6))
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)));
}
}
function createPlusN(n){
return function (x){
return x+n;
};
};
var f = createPlusN(2);
var g = createPlusN(5);
console.log(f(g(6)));
<?php
function createPlusN($n){
return function ($x) use($n){
return $x+$n;
};
};
$f = createPlusN(2);
$g = createPlusN(5);
echo $f($g(6));
def createPlusN(n: Int) =
(x: Int) => x+n
val f = createPlusN(2)
val g = createPlusN(5)
println(f(g(6)))
#!/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