JavaLambdaInternals icon indicating copy to clipboard operation
JavaLambdaInternals copied to clipboard

请教下sink之间是倒序查找的,那么如何保证执行操作的正确性?

Open yycer opened this issue 5 years ago • 1 comments

举个例子:

String[] s = {"1.0", "2.0", "3.0", "4.0", "5.0"};
Double ans = Stream.of(s)
		.map(Double::valueOf)
		.filter(d -> d > 2)
		.sorted(Comparator.reverseOrder())
		.limit(2)
		.reduce(Double::sum)
		.orElse(0d);

倒序执行第一个Intermediate Operation 时,也就是limit,如何保证不会获取"1.0", "2.0"?

yycer avatar Jul 28 '20 03:07 yycer

只是倒序遍历组装成一个sink,执行的时候还是正序执行的。

twwwww avatar Sep 15 '20 04:09 twwwww