Skip to content

mg52/splitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

splitter

Go LINQ Where

Installation

go get github.com/mg52/[email protected]

Usage:

package main

import (
	"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}]
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages