Skip to content

Commit

Permalink
custom method (#38)
Browse files Browse the repository at this point in the history
* custom method

* readme fix

GreaterThan is a better name
  • Loading branch information
kalaninja authored and ahmetb committed Sep 8, 2016
1 parent 28f0008 commit b1c935a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,31 @@ author := From(books).SelectMany( // make a flat array of authors
}).First() // take the first author
```

**Example: Implement a custom method that leaves only values greater than the specified threshold**
```go
type MyQuery Query

func (q MyQuery) GreaterThan(threshold int) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()

return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if item.(int) > threshold {
return
}
}

return
}
},
}
}

result := MyQuery(Range(1,10)).GreaterThan(5).Results()
```

**More examples** can be found in [documentation](https://godoc.org/github.com/ahmetalpbalkan/go-linq).

## Release Notes
Expand Down

0 comments on commit b1c935a

Please sign in to comment.