-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathselect-many.go
45 lines (40 loc) · 1.02 KB
/
select-many.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
package underscore
import "reflect"
func (m enumerable) SelectMany(selector interface{}) IEnumerable {
return enumerable{
Enumerator: func() IEnumerator {
var tempIterator IEnumerator
iterator := m.GetEnumerator()
selectorRV := reflect.ValueOf(selector)
return &enumerator{
MoveNextFunc: func() (valueRV reflect.Value, keyRV reflect.Value, ok bool) {
for !ok {
if tempIterator == nil {
ok = iterator.MoveNext()
if !ok {
return
}
selectorResultRV := getReturnValue(selectorRV, iterator)
tempIterator = chainFromValue(selectorResultRV).GetEnumerator()
}
if ok = tempIterator.MoveNext(); ok {
keyRV = tempIterator.GetKey()
valueRV = tempIterator.GetValue()
} else {
tempIterator = nil
}
}
return
},
}
},
}
}
func (m enumerable) SelectManyBy(fieldName string) IEnumerable {
getter := FieldValue(fieldName)
return m.SelectMany(func(value, _ interface{}) facade {
return facade{
getter(value),
}
})
}