import fj.data.List;
import fj.data.Option;
import static fj.data.Option.*;
import static fj.Ord.*;
import static fj.P.*;
import static fj.P2.*;
public class HigherOrderFunctionsExample {
public static void main(String[] args) {
List<Integer> numbers = List.list(1, 2, 3, 4, 5);
List<Integer> squareNumbers = numbers.map(x -> x * x);
List<Integer> evenNumbers = numbers.filter(x -> x % 2 == 0);
Option<Integer> sum = numbers.toStream().reduce((x, y) -> x + y);
}
}
import fj.F;
import fj.data.List;
public class FunctionCompositionExample {
public static void main(String[] args) {
F<Integer, Integer> add = x -> x + 1;
F<Integer, Integer> multiply = x -> x * 2;
F<Integer, Integer> composedFunction = add.andThen(multiply);
List<Integer> numbers = List.list(1, 2, 3, 4, 5);
List<Integer> transformedNumbers = numbers.map(composedFunction);
}
}
import fj.data.Option;
import static fj.data.Option.*;
import static fj.Ord.*;
import static fj.P.*;
import static fj.P2.*;
public class ErrorHandlingExample {
public static void main(String[] args) {
Option<Integer> maybeNumber = some(42);
Option<String> maybeString = maybeNumber.map(n -> n.toString());
}
}