Giter Site home page Giter Site logo

glinq's Introduction

glinq

Go port of DotNet LINQ using generics introduced in Go 1.18

Currently implemented

  • Where
  • Select
  • Range
  • Foreach
  • Min(By)
  • Max(By)
  • Average
  • Sum
  • First
  • Last
  • Skip(While)
  • Take(While)
  • Contains
  • Any
  • Join

(OrderBy And GroupBy will always access all items. For performance and ease of use reason I'll not implement them in IEnumerable way. Please use glinq/garray package instead)

Adapters:

  • FromSlice

  • FromMap

  • ReadLines (wrapping bufio.NewScanner)

  • sqlxq.Queryx (wrapping sqlx.Queryx)

  • ToSlice

  • ToMap

Also some similar utilities directly for slices in the glinq/garray package. These are more handful, without FromSlice/ToSlice conversion.

  • Sort(Descending)
  • SortBy(Descending)
  • Map
  • ToMap
  • Filter
  • Apply
  • RemoveIf
  • Contains
  • (Last)IndexOf
  • (Last)IndexWhere
  • First, Last
  • Concat
  • ShallowCopy
  • Sum
  • Average
  • GroupBy
  • Count
  • Reverse

Also a generic SyncMap type (should I separate it in another repository?)

  • Load
  • Store
  • Range(E)
  • Delete(If)
  • LoadAndDelete
  • LoadOrStore
  • LoadOrNew
  • LoadAndUpdate
  • ToSlice
  • Keys
  • Len
  • Clear
  • PopAll

And more to come...

usage example

package main

import (
	"fmt"

	"github.com/szmcdull/glinq/garray"
	. "github.com/szmcdull/glinq/unsafe"
)

func main() {
	numbers := garray.Concat([]int{1, 2, 3, 4, 5}, []int{6, 7, 8, 9, 10})
	numbersToRemove := Where(FromSlice(numbers), func(x int) bool {
		return x > 5
	})
	Do(numbersToRemove, func(x int) { fmt.Printf(`%d `, x) }) // 6 7 8 9 10
	fmt.Println(``)
	numbers = ToSlice(Where(FromSlice(numbers), func(x int) bool {
		return !Contains(numbersToRemove, x)
	}))
	fmt.Println(Any(Where(FromSlice(numbers), func(x int) bool { return x > 5 }))) // false
	Do(FromSlice(numbers), func(x int) { fmt.Printf(`%d `, x) })                   // 1 2 3 4 5
	fmt.Println(``)

	// Sorting
	l := []int{8, 6, 4, 2, 5, 3, 1}

	garray.Sort(l)
	fmt.Printf("%v\n", l) // [1 2 3 4 5 6 8]

	l2 := []string{`the`, `lazy`, `dog`, `jumps`, `over`, `the`, `silver`, `fox`}
	garray.SortByDescending(l2, func(x string) byte { return x[len(x)-1] }) // sort descending by the last character
	fmt.Printf("%v\n", l2)                                                  // [lazy fox jumps silver over dog the the]
}

More examples:

glinq's People

Contributors

szmcdull avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.