-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.go
54 lines (41 loc) · 1.19 KB
/
stream.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package stream
type BaseStreamer interface {
evaluateParallel()
parallel()
}
// Streamer 数据流接口
type Streamer interface {
/*
中间态操作,返回Streamer
垂直操作:map,filter,
水平操作:distinct,sorted,limit,skip, sourceStage 会改变
*/
Map(function Function) Streamer
Filter(predicate Predicate) Streamer
//FindFirst(predicate Predicate) Streamer
FlatMap(beStreamer BeStreamer) Streamer
Distinct(comparator Comparator) Streamer
Sorted(comparator Comparator) Streamer
Limit(limit int) Streamer
Skip(index int) Streamer
/*
终止操作,触发流水线真正的执行动作,无返回值。
*/
Reduce(reduceFun ReduceFun) interface{}
ForEach(consumer Consumer)
ToSlice(targetSlice interface{})
Count() int
AnyMatch(predicate Predicate) bool
}
// Predicate 断言
type Predicate func(v interface{}) bool
// Consumer 消费
type Consumer func(v interface{})
// Comparator 比较
type Comparator func(i, j interface{}) bool
// ReduceFun 归约
type ReduceFun func(i, j interface{}) interface{}
// Function 普通方法
type Function func(v interface{}) interface{}
// BeStreamer 构造流方法
type BeStreamer func(v interface{}) Streamer