package ink.wgink.gateway;

import java.util.function.*;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: LambdaTest
 * @Description:
 * @Author: wanggeng
 * @Date: 2021/4/16 10:05 上午
 * @Version: 1.0
 */
public class LambdaTest2 {

    public static void main(String[] args) {
        Function<Integer, Integer> result = x -> x;
        System.out.println(result.apply(1));

        Function<Integer, Function<Double, Double>> result2 = x -> y -> x + y;
        System.out.println(result2.apply(2).apply(2.2));

        Function<Integer, Function<Integer, Function<Integer, Integer>>> result3 = x -> y -> z -> x + y + z;
        System.out.println("结果:"+ result3.apply(1).apply(2).apply(3));
        int[] nums = {1, 2, 3};
        Function f = result3;
        for(int i = 0; i < nums.length; i++) {
            Object n = f.apply(nums[i]);
            if(n instanceof Function) {
                f = (Function) n;
            } else {
                System.out.println("循环结果:" + n);
            }
        }
    }

}
