-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtraversable.go
67 lines (52 loc) · 2.04 KB
/
traversable.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
59
60
61
62
63
64
65
66
67
package monadgo
// Traversable represents a scala-like Traversable trait.
type Traversable interface {
sequence
// Size returns the size.
Size() int
// Map applies function f to all elements in seq s.
// f: func(T) X
// returns a Traversable with element type X.
Map(f interface{}) Traversable
// FlatMap applies f to all elements and builds a new Travesable from result.
// f: func(T) Traversable[X], X can be Go slice, or map.
// returns a new Traversable with element type X.
FlatMap(f interface{}) Traversable
// Forall tests whether a predicate holds for all elements.
// f: func(T) bool
Forall(f interface{}) bool
// Foreach applies f to all element.
// f: func(T)
Foreach(f interface{})
// Fold folds the elements using specified associative binary operator.
// z: func() T or value of type T.
// f: func(T, T) T
// returns value with type T
Fold(z, f interface{}) interface{}
// Reduce reduces the elements of this using the specified associative binary operator.
// f: func(T, T)
// returns value with type T.
Reduce(f interface{}) interface{}
// GroupBy returns Map with K -> Go slice. Key is the result of f. Collect elements into a slice with same resulting key value.
// f: func(T) K
// returns Map(K -> Go slice)
GroupBy(f interface{}) Map
// Exists tests whether a predicate holds for at least one element of this sequence.
// f: func(T) bool
Exists(f interface{}) bool
// Find returns the first element satisfying f,
// otherwise return None.
Find(f interface{}) Option
// Filter retuns all elements satisfying f.
// f: func(T) bool
Filter(f interface{}) Traversable
// MkString displays all elements in a string using start, end, and separator sep.
MkString(start, sep, end string) string
// Split splits this into a unsatisfying and satisfying pair according to f.
// f: func(T) bool
Split(f interface{}) Tuple2
// Collect returns elements satisfying pf.
// pf is a partial function consisting of Condition func(T) bool and Action func(T) X.
// returns a new Traversable[X]
Collect(pf PartialFunc) Traversable
}