Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,33 @@
public class Compose {
// Java doesn't have function type so we define an interface
// of function objects instead
public interface Fun<A,B> {
B call(A x);
}
public static <A,B,C> Fun<A,C> compose(final Fun<B,C> f, final Fun<A,B> g) {
return new Fun<A,C>() {
public C call(A x) {
return f.call(g.call(x));
}
};
}
public static void main(String[] args) {
Fun<Double,Double> sin = new Fun<Double,Double>() {
public Double call(Double x) {
return Math.sin(x);
}
};
Fun<Double,Double> asin = new Fun<Double,Double>() {
public Double call(Double x) {
return Math.asin(x);
}
};
Fun<Double,Double> sin_asin = compose(sin, asin);
System.out.println(sin_asin.call(0.5)); // prints "0.5"
}
}

View file

@ -0,0 +1,9 @@
import java.util.function.Function;
public class Compose {
public static void main(String[] args) {
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"
}
}