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
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.function.Function; | |
interface Functor<T, F extends Functor<?,?>> { | |
<R> F map (Function<T, R> f); | |
} | |
class FList<T> implements Functor<T, FList<?>> { | |
private final List<T> list; |
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
import java.math.BigInteger; | |
import java.util.Arrays; | |
import java.util.stream.IntStream; | |
//var r =IntStream.rangeClosed(1,5) | |
// .reduce(1,(x,y) -> x * y); | |
// //.forEach(System.out::println); | |
static BigInteger factorial(int n){ | |
return IntStream.rangeClosed(1, n) |
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
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
import java.util.Optional; | |
import java.util.function.Function; | |
import java.util.stream.Stream; | |
@FunctionalInterface | |
interface ExFunction<E, F> { | |
F apply (E e) throws Throwable; | |
static <E, F> Function<E, Optional<F>> wrap (ExFunction<E, F> op){ |
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
/* | |
This example shows how to group employees by their departments. | |
The intention of this example, to show the use of the <b>Collectors.groupingBy</b> | |
functionality. | |
*/ | |
import java.util.List; | |
import java.util.stream.Collectors; | |
class Dept { |