본문 바로가기

CS/Java

Java FP 1. Lambda expressions and method references

Functional Programming in Java! 그 첫번째, lambda expression이다.

람다식 쓰는 자체는 어려운 건 없어서 일단 용법만 step ik에 있는 거 그대로 가져왔다.

// a simple way to write a lambda expression
BiFunction<Integer, Integer, Integer> sum = (x, y) -> x + y;

// if the only one argument
Function<Integer, Integer> identity = x -> x; // (x) -> x; is valid too

// without type inference
Function<Integer, Integer> mult = (Integer x) -> x * 2;

// with multiple statements
Function<Integer, Integer> adder = (x) -> {
    x += 5;
    x += 10;
    return x;
};

 

 

출처 : https://stepik.org/course/1595

 

Java. Functional programming

The course introduces elements of functional programming in Java 8. After completing this course, you should have a basic understanding of lambda expressions, functional interfaces, stream API, lazy evaluation, currying and monads.

stepik.org

'CS > Java' 카테고리의 다른 글

Java FP 5. Monads  (7) 2020.04.07
Java FP 4. Currying  (5) 2020.04.07
Java FP 3. Streams  (4) 2020.03.30
Java FP 2. Functions are objects  (13) 2020.03.26