Skip to content

Commit b1c935a

Browse files
kalaninjaahmetb
authored andcommitted
custom method (#38)
* custom method * readme fix GreaterThan is a better name
1 parent 28f0008 commit b1c935a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,31 @@ author := From(books).SelectMany( // make a flat array of authors
7171
}).First() // take the first author
7272
```
7373

74+
**Example: Implement a custom method that leaves only values greater than the specified threshold**
75+
```go
76+
type MyQuery Query
77+
78+
func (q MyQuery) GreaterThan(threshold int) Query {
79+
return Query{
80+
Iterate: func() Iterator {
81+
next := q.Iterate()
82+
83+
return func() (item interface{}, ok bool) {
84+
for item, ok = next(); ok; item, ok = next() {
85+
if item.(int) > threshold {
86+
return
87+
}
88+
}
89+
90+
return
91+
}
92+
},
93+
}
94+
}
95+
96+
result := MyQuery(Range(1,10)).GreaterThan(5).Results()
97+
```
98+
7499
**More examples** can be found in [documentation](https://godoc.org/github.com/ahmetalpbalkan/go-linq).
75100

76101
## Release Notes

0 commit comments

Comments
 (0)