首页 Java Streams vs. Reactive Streams
文章
取消

Java Streams vs. Reactive Streams

Java: imperative + object-oriented

Michael Feather:

​ “In OPP we encapsulate the moving parts; in FP we eliminate the moving parts.”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

//double of even numbers
List<Integer> doubled = new ArrayList<>();

for (int i = 0; i < numbers.size(); i++) {
	if (numbers.get(i) % 2 == 0) {
		doubled.add(numbers.get(i) * 2);
	}
}
System.out.println(doubled);

System.out.println(
	numbers.stream()	
		.filter( e -> e % 2 == 0)
		.map( e -> e * 2)
		.collect(toList()));

functional programming == functional composition + lazy evaluation

Collection Pipeline Pattern

Stream is not a data structure it is an abstraction of functions

bucket vs pipeline

List/Set Stream

dataflow computing

Serverless

image-20200126043305570

本文由作者按照 CC BY 4.0 进行授权