Skip to content

golist provides useful functions for list operations in Go.

License

Notifications You must be signed in to change notification settings

schoukri/golist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golist

Build Status Software License Go Doc Go Report Card

Golist provides useful functions for common list operations in Go.

Introduction

Working with lists of data in Go using the built-in slice data type and operators can sometimes be a pain. Simple and common operations such as sorting, removing duplicates, and manipulating data can often requires a lot of boilerplate code to accomplish. This package simplifies working with slices by providing easy to use methods for common operations. The methods can also be chained together to enable complex operations on the underlying data with a lot less code, but still highly-readable and easy to maintain.

Example

Here is an example that starts with a slice of integers, multiplies each item by 2, selects only those items that are greater than 20, removes any duplicates, then finally sorts the integers in ascending order.

	s := golist.NewSliceInt(-5, 3, 2, 21, 0, 40, -4, -20, 100, 40, -9, 18, 21, -33, 40)

	s.Transform(func(a int) int {
		return a * 2
	}).Filter(func(a int) bool {
		return a > 20
	}).Unique().Sort()

	for _, value := range s.Data() {
		fmt.Println(value)
	}

	// Output:
	// 36
	// 42
	// 80
	// 200

Inspiration

Warning

Golist is in active development and is not yet ready for use in production. The API is experimental and is subject to change without notice. Suggestions or contributions to improve Golist and help shape its design are welcome and encouraged!

About

golist provides useful functions for list operations in Go.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages