-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamer.go
58 lines (45 loc) · 1.39 KB
/
streamer.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
55
56
57
58
package streamer
type Iterator interface {
Next() (interface{}, bool)
}
//
type Stream struct {
input Iterator
}
func NewStream(input Iterator) (res *Stream) {
res = &Stream{input: input}
return
}
func (st *Stream) Next() (interface{}, bool) { return st.input.Next() }
func (st *Stream) Map(mapFn func(x interface{}) interface{}) *Stream {
iterator := newMapperStream(st.input, mapFn)
return NewStream(iterator)
}
func (st *Stream) ChunkBy(chunkFn func(x interface{}) interface{}) *Stream {
iterator := newChunkByStream(st.input, chunkFn)
return NewStream(iterator)
}
func (st *Stream) ChunkEvery(chunkSize int) *Stream {
iterator := newChunkEveryStream(st.input, chunkSize)
return NewStream(iterator)
}
func (st *Stream) Skip(skipCount int) *Stream {
iterator := newSkipStream(st.input, skipCount)
return NewStream(iterator)
}
func (st *Stream) SkipWhile(skipFn func(interface{}) bool) *Stream {
iterator := newSkipWhileStream(st.input, skipFn)
return NewStream(iterator)
}
func (st *Stream) Filter(filterFn func(interface{}) bool) *Stream {
iterator := newFilterStream(st.input, filterFn)
return NewStream(iterator)
}
func (st *Stream) Take(takeCount int) *Stream {
iterator := newTakeStream(st.input, takeCount)
return NewStream(iterator)
}
func (st *Stream) TakeWhile(takeFn func(interface{}) bool) *Stream {
iterator := newTakeWhileStream(st.input, takeFn)
return NewStream(iterator)
}