Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,11 @@
defmodule RC do
def compose(f, g), do: fn(x) -> f.(g.(x)) end
def multicompose(fs), do: List.foldl(fs, fn(x) -> x end, &compose/2)
end
sin_asin = RC.compose(&:math.sin/1, &:math.asin/1)
IO.puts sin_asin.(0.5)
IO.puts RC.multicompose([&:math.sin/1, &:math.asin/1, fn x->1/x end]).(0.5)
IO.puts RC.multicompose([&(&1*&1), &(1/&1), &(&1*&1)]).(0.5)

View file

@ -0,0 +1,8 @@
final times2 = { it * 2 }
final plus1 = { it + 1 }
final plus1_then_times2 = times2 << plus1
final times2_then_plus1 = times2 >> plus1
assert plus1_then_times2(3) == 8
assert times2_then_plus1(3) == 7

View file

@ -1,12 +1,8 @@
import java.util.function.Function;
public class Compose {
public static <A,B,C> Function<A,C> compose(Function<B,C> f, Function<A,B> g) {
return x -> f.apply(g.apply(x));
}
public static void main(String[] args) {
Function<Double,Double> sin_asin = compose(Math::sin, Math::asin);
Function<Double,Double> sin_asin = ((Function<Double,Double>)Math::sin).compose(Math::asin);
System.out.println(sin_asin.apply(0.5)); // prints "0.5"
}

View file

@ -0,0 +1,13 @@
import java.util.function.Function;
public class Compose {
public static <A,B,C> Function<A,C> compose(Function<B,C> f, Function<A,B> g) {
return x -> f.apply(g.apply(x));
}
public static void main(String[] args) {
Function<Double,Double> sin_asin = compose(Math::sin, Math::asin);
System.out.println(sin_asin.apply(0.5)); // prints "0.5"
}
}

View file

@ -0,0 +1,3 @@
sub triple($n) { 3 * $n }
my &f = &triple &prefix:<-> { $^n + 2 };
say &f(5); # Prints "-21".

View file

@ -0,0 +1,7 @@
function g ($x) {
$x + $x
}
function f ($x) {
$x*$x*$x
}
f (g 1)

View file

@ -0,0 +1,4 @@
function fg (${function:f}, ${function:g}, $x) {
f (g $x)
}
fg f g 1