Generic-based collection tools

go-collection

go collection is a tool implemented using generic, it can help you process slice/map data quickly and easily convert between them.

Note: To use this project, you need to upgrade to go1.18 version. Some methods cannot be implemented in the 1.18 version, and will be supported after version 1.19 supports type methods.

πŸš€ Install

go get -u github.com/wwaayyaa/go-collection

✏️ Usage

import collect "github.com/wwaayyaa/go-collection"

Slice example

// filter  
NewSlice[int]([]int{1, 2, 3, 4, 5, 6}).
Filter(func (x int) bool { return x <= 3 }).
All() // [1,2,3]

//join
NewSlice[int]([]int{1, 2, 3, 4, 5, 6}).
Except(func (x int) bool { return x <= 3 }).
Join(func (v int) string { return strconv.Itoa(v) }, "-")
// 1-2-3

//map
NewSlice[string]([]string{"world", "girl"}).
Map(func (k int, v string) string { return "hello " + v }).
All() // ["hello world", "hello girl"]

Maps example

//["a", "z"]
NewMapCollection(map[string]int{"a": 1, "z": 100}).Keys()

//[1, 100]
NewMapCollection(map[string]int{"a": 1, "z": 100}).Values()

πŸ“– API

Slice

  • Len
  • First
  • Last
  • Get
  • Put
  • Prepend
  • Shift
  • Push
  • Pop
  • Find
  • Index
  • Each
  • Map
  • Transform
  • All
  • Contains
  • Filter
  • Reject
  • Concat
  • Join
  • Clone
  • Tap
  • ToJson
  • Empty
  • Diff
  • Merge
  • Reverse
  • Slice
  • Delete
  • Chunk
  • Uniq
  • Shuffle
  • Keys
  • Values
  • Only
  • Except
  • Reduce
  • FlatMap
  • GroupBy
  • KeyBy
  • Flatten

Map

  • All
  • Count
  • Empty
  • Keys
  • Values
  • Entries
  • FromEntries
  • Has
  • Get
  • Put
  • Pull
  • Union
  • Intersect
  • Diff
  • SymmetricDiff
Similar Resources

Collection of unusual generics usecases in Go

Unusual Generics Type parameters or Generics in Go designed to reduce boilerplate for container data types like lists, graphs, etc. and functions like

Dec 14, 2022

A collection of functional operators for golang with generics

fn fn is a collection of go functional operators with generics Getting Started P

Jul 8, 2022

Go-Utils is a library containing a collection of Golang utilities

Go-Utils is a library containing a collection of Golang utilities

Jun 2, 2022

Code generation tools for Go.

interfaces Code generation tools for Go's interfaces. Tools available in this repository: cmd/interfacer cmd/structer cmd/interfacer Generates an inte

Dec 23, 2022

A directory of hardware related libs, tools, and tutorials for Go

Go + hardware This repo is a directory of tools, packages and tutorials to let you introduce Go in your hardware projects. Why Go? Go can target platf

Dec 30, 2022

gqlanalysis makes easy to develop static analysis tools for GraphQL in Go.

gqlanalysis makes easy to develop static analysis tools for GraphQL in Go.

gqlanalysis gqlanalysis defines the interface between a modular static analysis for GraphQL in Go. gqlanalysis is inspired by go/analysis. gqlanalysis

Dec 14, 2022

Little Bug Bounty & Hacking Toolsβš”οΈ

Little Bug Bounty & Hacking Tools βš”οΈ

Jan 7, 2023

common tools for golang

utils common tools for golang package main

Dec 27, 2021

Source code of Liteloader Tools

LiteLoader Tools This repository store the source code of some LiteLoader Tools Prebuilt Binary see /bin folder Image2Binary [Golang] convert Image(jp

Aug 30, 2022
Di - A (very) WIP Go 1.18+ generic dependency injection package based on type reflection

di A (very) WIP Go 1.18+ generic dependency injection package based on type refl

Apr 26, 2022
πŸš€ GoDI: Generic based DI in Go

?? GoDI: Generic based DI in Go Installation DI: go get -u github.com/MaximZayats/godi/ import "github.com/MaximZayats/godi/di" CMD: go get -u github.

Aug 14, 2022
A better Generic Pool (sync.Pool)
A better Generic Pool (sync.Pool)

This package is a thin wrapper over the Pool provided by the sync package. The Pool is an essential package to obtain maximum performance by reducing the number of memory allocations.

Dec 1, 2022
Package ethtool allows control of the Linux ethtool generic netlink interface.

ethtool Package ethtool allows control of the Linux ethtool generic netlink interface.

Dec 14, 2022
Go library for decoding generic map values into native Go structures and vice versa.

mapstructure mapstructure is a Go library for decoding generic map values to structures and vice versa, while providing helpful error handling. This l

Dec 28, 2022
conditiond is a generic constraint and policy evaluator.

conditiond conditiond is a generic constraint and policy evaluator. This tool lets you define constraints in data and evaluate them at run time. It's

Dec 5, 2022
Some utility functions for generic types in Go.

GOUF - Utility Functions for generic types Go team released Go 1.18 beta recently with support for Generics(a.k.a type parameters). This package provi

Apr 13, 2022
Generic Free List implementation to reuse memory and avoid allocations

gofl GOFL provides a Generic Free List implementation for Go. Installation This

Oct 17, 2022
Slice - provides generic Map, Reduce and Filter functions for Go.

slice slice is a simple Go package to provide generic versions of Map, Reduce and Filter on slices. I mainly wrote it as an exercise to get more famil

Jan 1, 2023
A collection of small Go utilities to make life easier.

The simplego package provides a collection of Go utilities for common tasks.

Jan 4, 2023