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
| public class Main { | |
| @FunctionalInterface | |
| interface Function3 <A, B, C, R> { | |
| public R apply (A a, B b, C c); | |
| } | |
| public static void main(String[] args) { | |
| BiFunction<Integer, Integer, Integer> add = Math::addExact; | |
| BiFunction<Integer, Integer, Integer> subtract = Math::subtractExact; |
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 Empty<A> { | |
| A empty(); | |
| } |
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
| class EmptyInt implements Empty<Integer>{ | |
| @Override | |
| public Integer empty() { | |
| return 0; | |
| } | |
| } |
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 Empty<A> { | |
| A empty(); | |
| static Empty<Integer> emptyInt(){ | |
| return new EmptyInt(); | |
| } | |
| } |
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 Empty<A> { | |
| A empty(); | |
| static Empty<Integer> emptyInt(){ | |
| return () -> 0; | |
| } | |
| } |
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
| final class Functions { | |
| static <T> Tuple2<T, T> twoEmpties(Empty<T> empty) { | |
| return Tuple.of(empty.empty(), empty.empty()); | |
| } | |
| ... | |
| } |
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
| var xAndY = twoEmpties(emptyInt()); | |
| System.out.println("{" + xAndY._1() + ", " + xAndY._2() + "}"); |
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
| val xAndY = twoEmpties() |
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 Show<A> { | |
| String show(A a); | |
| static <X, Y> Show<Tuple2<X, Y>> showTuple() { | |
| return t -> "{" + t._1() + ", " + t._2() + "}"; | |
| } | |
| } |
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
| static <A> String show(A a, Show<A> sh) { | |
| return sh.show(a); | |
| } |
OlderNewer