File tree 7 files changed +32
-13
lines changed
7 files changed +32
-13
lines changed Original file line number Diff line number Diff line change 9
9
\_/__/
10
10
```
11
11
12
- # Underscore.go [ ![ GoDoc] ( https://godoc.org/github.com/ahl5esoft/golang-underscore?status.svg )] ( https://godoc.org/github.com/ahl5esoft/golang-underscore ) [ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/ahl5esoft/golang-underscore )] ( https://goreportcard.com/report/github.com/ahl5esoft/golang-underscore ) ![ Version] ( https://img.shields.io/badge/version-2.2.0 -green.svg )
12
+ # Underscore.go [ ![ GoDoc] ( https://godoc.org/github.com/ahl5esoft/golang-underscore?status.svg )] ( https://godoc.org/github.com/ahl5esoft/golang-underscore ) [ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/ahl5esoft/golang-underscore )] ( https://goreportcard.com/report/github.com/ahl5esoft/golang-underscore ) ![ Version] ( https://img.shields.io/badge/version-2.2.1 -green.svg )
13
13
like <a href =" http://underscorejs.org/ " >underscore.js</a > and C# LINQ, but for Go
14
14
15
15
## Installation
Original file line number Diff line number Diff line change 4
4
5
5
require (
6
6
github.com/davecgh/go-spew v1.1.1 // indirect
7
- github.com/go-playground/assert/v2 v2.0.1
8
7
github.com/stretchr/testify v1.6.1
9
8
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
10
9
)
Original file line number Diff line number Diff line change @@ -2,9 +2,6 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
2
2
github.com/davecgh/go-spew v1.1.0 /go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38 =
3
3
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c =
4
4
github.com/davecgh/go-spew v1.1.1 /go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38 =
5
- github.com/go-playground/assert v1.2.1 h1:ad06XqC+TOv0nJWnbULSlh3ehp5uLuQEojZY5Tq8RgI =
6
- github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A =
7
- github.com/go-playground/assert/v2 v2.0.1 /go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4 =
8
5
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM =
9
6
github.com/pmezard/go-difflib v1.0.0 /go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4 =
10
7
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4 =
Original file line number Diff line number Diff line change @@ -42,8 +42,8 @@ func Test_Group(t *testing.T) {
42
42
t ,
43
43
res ,
44
44
map [string ][]int {
45
- "odd" : [] int {1 , 3 , 5 },
46
- "even" : [] int {2 , 4 },
45
+ "odd" : {1 , 3 , 5 },
46
+ "even" : {2 , 4 },
47
47
},
48
48
)
49
49
}
Original file line number Diff line number Diff line change 1
1
package underscore
2
2
3
- import "reflect"
3
+ import (
4
+ "reflect"
5
+ )
4
6
5
7
func (m enumerable ) Object () IEnumerable {
6
8
iterator := m .GetEnumerator ()
@@ -9,8 +11,12 @@ func (m enumerable) Object() IEnumerable {
9
11
return & enumerator {
10
12
MoveNextFunc : func () (valueRV reflect.Value , keyRV reflect.Value , ok bool ) {
11
13
if ok = iterator .MoveNext (); ok {
12
- keyRV = iterator .GetValue ().Index (0 ).Elem ()
13
- valueRV = iterator .GetValue ().Index (1 ).Elem ()
14
+ keyRV = iterator .GetValue ().Index (0 )
15
+ valueRV = iterator .GetValue ().Index (1 )
16
+ if keyRV .Kind () == reflect .Interface {
17
+ keyRV = keyRV .Elem ()
18
+ valueRV = valueRV .Elem ()
19
+ }
14
20
}
15
21
16
22
return
Original file line number Diff line number Diff line change 6
6
"github.com/stretchr/testify/assert"
7
7
)
8
8
9
- func Test_Object (t * testing.T ) {
9
+ func Test_Object_interface (t * testing.T ) {
10
10
src := [][]interface {}{
11
11
{"a" , 1 },
12
12
{"b" , 2 },
@@ -22,3 +22,20 @@ func Test_Object(t *testing.T) {
22
22
},
23
23
)
24
24
}
25
+
26
+ func Test_Object_string (t * testing.T ) {
27
+ src := [][]string {
28
+ {"a" , "a1" },
29
+ {"b" , "b1" },
30
+ }
31
+ res := make (map [string ]string )
32
+ Chain (src ).Object ().Value (& res )
33
+ assert .EqualValues (
34
+ t ,
35
+ res ,
36
+ map [string ]string {
37
+ "a" : src [0 ][1 ],
38
+ "b" : src [1 ][1 ],
39
+ },
40
+ )
41
+ }
Original file line number Diff line number Diff line change @@ -19,8 +19,8 @@ func Test_Value(t *testing.T) {
19
19
t ,
20
20
res ,
21
21
map [string ][]int {
22
- "odd" : [] int {1 , 3 },
23
- "even" : [] int {2 , 4 },
22
+ "odd" : {1 , 3 },
23
+ "even" : {2 , 4 },
24
24
},
25
25
)
26
26
}
You can’t perform that action at this time.
0 commit comments