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.1.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.1.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
@@ -19,7 +19,7 @@ like <a href="http://underscorejs.org/">underscore.js</a> and C# LINQ, but for G
19
19
$ go get -u github.com/ahl5esoft/golang-underscore
20
20
21
21
## Lack
22
- * Except/ExceptBy/Reject/RejectBy/Reverse/ReverseBy/ ThenBy
22
+ * ThenBy
23
23
24
24
## Documentation
25
25
@@ -48,6 +48,8 @@ like <a href="http://underscorejs.org/">underscore.js</a> and C# LINQ, but for G
48
48
* [ ` Property ` ] ( #property ) , [ ` PropertyRV ` ] ( #propertyRV )
49
49
* [ ` Range ` ] ( #range )
50
50
* [ ` Reduce ` ] ( #aggregate )
51
+ * [ ` Reject ` ] ( #reject ) , [ ` RejectBy ` ] ( #rejectBy )
52
+ * [ ` Reverse ` ] ( #reverse ) , [ ` ReverseBy ` ] ( #reverseBy )
51
53
* [ ` Select ` ] ( #select ) , [ ` SelectBy ` ] ( #selectBy )
52
54
* [ ` SelectMany ` ] ( #selectMany ) , [ ` SelectManyBy ` ] ( #selectManyBy )
53
55
* [ ` Size ` ] ( #count )
@@ -113,11 +115,11 @@ ok := Chain([]testModel{
113
115
114
116
<a name =" allBy " />
115
117
116
- ### AllBy(properties ) bool
118
+ ### AllBy(fields ) bool
117
119
118
120
__ Arguments__
119
121
120
- * ` properties ` - map[ string] interface{}
122
+ * ` fields ` - map[ string] interface{}
121
123
122
124
__ Return__
123
125
@@ -163,11 +165,11 @@ ok := Chain([]testModel{
163
165
164
166
<a name =" anyBy " />
165
167
166
- ### AnyBy(properties ) bool
168
+ ### AnyBy(fields ) bool
167
169
168
170
__ Arguments__
169
171
170
- * ` properties ` - map[ string] interface{}
172
+ * ` fields ` - map[ string] interface{}
171
173
172
174
__ Return__
173
175
@@ -323,11 +325,11 @@ Chain([][]int{
323
325
324
326
<a name =" findBy " />
325
327
326
- ### FindBy(properties ) IEnumerable
328
+ ### FindBy(fields ) IEnumerable
327
329
328
330
__ Arguments__
329
331
330
- * ` properties ` - map[ string] interface{}
332
+ * ` fields ` - map[ string] interface{}
331
333
332
334
__ Examples__
333
335
@@ -372,11 +374,11 @@ index := Chain(src).FindIndex(func(r testModel, _ int) bool {
372
374
373
375
<a name =" findIndexBy " />
374
376
375
- ### FindIndexBy(properties ) int
377
+ ### FindIndexBy(fields ) int
376
378
377
379
__ Arguments__
378
380
379
- * ` properties ` - map[ string] interface{}
381
+ * ` fields ` - map[ string] interface{}
380
382
381
383
__ Return__
382
384
@@ -530,12 +532,12 @@ if IsArray(map[string]int{}) {
530
532
531
533
<a name =" isMatch " />
532
534
533
- ### IsMatch(element, properties ) bool
535
+ ### IsMatch(element, fields ) bool
534
536
535
537
__ Arguments__
536
538
537
539
* ` element ` - object
538
- * ` properties ` - map[ string] interface{}
540
+ * ` fields ` - map[ string] interface{}
539
541
540
542
__ Examples__
541
543
@@ -763,6 +765,100 @@ Range2(0, 3, 2).Value(&res)
763
765
// res = [0 2]
764
766
```
765
767
768
+ <a name =" reject " />
769
+
770
+ ### Reject(predicate) IEnumerable
771
+
772
+ __ Arguments__
773
+
774
+ * ` predicate ` - func(element or value, index or key) bool
775
+
776
+ __ Examples__
777
+
778
+ ``` go
779
+ arr := []int {1 , 2 , 3 , 4 }
780
+ var res []int
781
+ Chain (arr).Reject (func (n, i int ) bool {
782
+ return n%2 == 0
783
+ }).Value (&res)
784
+ // res = [1, 3]
785
+ ```
786
+
787
+ __ Same__
788
+
789
+ * ` Except `
790
+
791
+ <a name =" rejectBy " />
792
+
793
+ ### RejectBy(fields) IEnumerable
794
+
795
+ __ Arguments__
796
+
797
+ * ` fields ` - map[ string] interface{}
798
+
799
+ __ Examples__
800
+
801
+ ``` go
802
+ arr := []testModel{
803
+ {ID: 1 , Name: " one" },
804
+ {ID: 2 , Name: " two" },
805
+ {ID: 3 , Name: " three" },
806
+ }
807
+ var res []testModel
808
+ Chain (arr).RejectBy (map [string ]interface {}{
809
+ " Id" : 1 ,
810
+ }).Value (&res)
811
+ // res = []testModel{ {ID: 2, Name: "two"}, {ID: 3, Name: "three"} }
812
+ ```
813
+
814
+ __ Same__
815
+
816
+ * ` ExceptBy `
817
+
818
+ <a name =" reverse " />
819
+
820
+ ### Reverse(selector) IEnumerable
821
+
822
+ __ Arguments__
823
+
824
+ * ` selector ` - func(element, index or key) anyType
825
+
826
+ __ Examples__
827
+
828
+ ``` go
829
+ src := []testModel{
830
+ {ID: 2 , Name: " two" },
831
+ {ID: 1 , Name: " one" },
832
+ {ID: 3 , Name: " three" },
833
+ }
834
+ var res []testModel
835
+ Chain (src).Reverse (func (r testModel, _ int ) int {
836
+ return r.ID
837
+ }).Value (&res)
838
+ // res = []testModel{ {ID: 3, Name: "three"}, {ID: 2, Name: "two"}, {ID: 1, Name: "one"} }
839
+ ```
840
+
841
+ <a name =" reverseBy " />
842
+
843
+ ### ReverseBy(fieldName) IEnumerable
844
+
845
+ __ Arguments__
846
+
847
+ * ` fieldName ` - string
848
+
849
+ __ Examples__
850
+
851
+ ``` go
852
+ src := []testModel{
853
+ {ID: 2 , Name: " two" },
854
+ {ID: 1 , Name: " one" },
855
+ {ID: 3 , Name: " three" },
856
+ }
857
+ var res []testModel
858
+ Chain (src).ReverseBy (" id" ).Value (&res)
859
+ // res = []testModel{ {ID: 3, Name: "three"}, {ID: 2, Name: "two"}, {ID: 1, Name: "one"} }
860
+ ```
861
+
766
862
<a name =" select " />
767
863
768
864
### Select(selector) IEnumerable
@@ -946,11 +1042,11 @@ __Same__
946
1042
947
1043
<a name =" whereBy " />
948
1044
949
- ### WhereBy(properties ) IEnumerable
1045
+ ### WhereBy(fields ) IEnumerable
950
1046
951
1047
__ Arguments__
952
1048
953
- * ` properties ` - map[ string] interface{}
1049
+ * ` fields ` - map[ string] interface{}
954
1050
955
1051
__ Examples__
956
1052
@@ -974,7 +1070,7 @@ __Same__
974
1070
975
1071
## Release Notes
976
1072
~~~
977
- v2.1.0 (2019-06-27 )
1073
+ v2.1.0 (2020-11-17 )
978
1074
* IEnumerable增加Order、OrderBy、Sort、SortBy
979
1075
* IEnumerable.Aggregate(memo interface{}, fn interface{}) -> IEnumerable.Aggregate(fn interface{}, memo interface{})
980
1076
~~~
0 commit comments