Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mg52/splitter
https://github.com/mg52/splitter
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mg52/splitter
- Owner: mg52
- Created: 2023-01-22T10:16:05.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-23T12:01:33.000Z (almost 2 years ago)
- Last Synced: 2024-06-21T09:55:29.686Z (5 months ago)
- Language: Go
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# splitter
Go LINQ Where
## Installation
go get github.com/mg52/[email protected]
## Usage:
```go
package mainimport (
"fmt"
"github.com/mg52/splitter"
)type Temperature struct {
Id int `json:"id"`
Value float64 `json:"value"`
Type string `json:"type"`
}var temperatures []Temperature
func main() {
temperatures = append(temperatures, Temperature{
Id: 0,
Value: 15.3,
Type: "Celsius",
})
temperatures = append(temperatures, Temperature{
Id: 1,
Value: 27.4,
Type: "Celsius",
})
temperatures = append(temperatures, Temperature{
Id: 2,
Value: 16.5,
Type: "Celsius",
})
temperatures = append(temperatures, Temperature{
Id: 3,
Value: 94.9,
Type: "Fahrenheit",
})
temperatures = append(temperatures, Temperature{
Id: 4,
Value: 80.2,
Type: "Fahrenheit",
})
temperatures = append(temperatures, Temperature{
Id: 5,
Value: 75.4,
Type: "Fahrenheit",
})clauses := []splitter.Clause{
{
Key: "Type",
Method: "==",
Val: "Fahrenheit",
},
{
Key: "Value",
Method: ">=",
Val: 75.6,
},
}actual, err := splitter.Where(temperatures, clauses)
if err != nil {
fmt.Println(err.Error())
}fmt.Println(actual)
// output: [{3 94.9 Fahrenheit} {4 80.2 Fahrenheit}]
}
```