Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/life4/genesis
All generic functions for Go you ever need!
https://github.com/life4/genesis
elixir enum erlang fp functional-programming generic generic-programming generics go golang goroutine map maps slice slices
Last synced: 1 day ago
JSON representation
All generic functions for Go you ever need!
- Host: GitHub
- URL: https://github.com/life4/genesis
- Owner: life4
- License: mit
- Created: 2019-09-13T15:11:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-11-19T18:59:43.000Z (2 months ago)
- Last Synced: 2025-01-25T04:14:30.520Z (8 days ago)
- Topics: elixir, enum, erlang, fp, functional-programming, generic, generic-programming, generics, go, golang, goroutine, map, maps, slice, slices
- Language: Go
- Homepage: https://pkg.go.dev/github.com/life4/genesis
- Size: 1.08 MB
- Stars: 346
- Watchers: 6
- Forks: 19
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Genesis
Generic functions for Go. Bringing the beauty of functional programming in Go 1.18+.
**ð Features:**
+ ð ïļ Over 170 generic functions for channels, maps, and slices.
+ ðŠ Uses the power of Go 1.18+ generics.
+ ð§ No code generation.
+ ðŠķ No dependencies (except [is](https://github.com/matryer/is) for testing).
+ ð Pure Go.
+ ðŠĐ Sync and async versions of all the main functions.**ðĻ When to use:**
+ ð **In a big project**. More the project grows, more you find yourself writing boring generic code like "Min". Break the cycle.
+ ðĪ **In a team project**. Each line of code you write means higher maintenance cost that in turn means loosing time and money.
+ ðķ **In a pet project**. Leave the boring stuff to us, focus on the fun parts.
+ ð **When readability matters**. `slices.Shrink` is a function with a human-friendly name and documentation. `s[:len(s):len(s)]` is a jibberish and black magic. Prefer the former.
+ ð **When you miss some conveniences** that come in other languages out-of-the-box.
+ ð **When you write a highly concurrent code** and don't want to manually implement code for cancellation, results collection and ordering, worker groups, context, etc.**ðĶ What's inside**:
+ `Filter`, `Map`, and `Reduce` for data processing on steroids.
+ `FilterAsync`, `MapAsync`, and `ReduceAsync` for making your code fast and concurrent with a single line of code.
+ `Grow` and `Shrink` for reducing memory allocations.
+ `Permutations` and `Product` for simple iterations.
+ `Shuffle` and `Sort` for randomization.
+ `Any` and `All` for simple flow control.
+ `Range`, `Count`, and `Cycle` for generating sequences.And much more.
## ðū Installation
```bash
go get github.com/life4/genesis
```## ð Examples
Find the minimal value in a slice of ints:
```go
lambdas.Must(slices.Min([]int{42, 7, 13})) == 7
```Double values in a slice of ints:
```go
slices.Map([]int{4, 8, 15}, func(el int) int { return el * 2 })
```Concurrently check status codes for multiple URLs:
```go
urls := []string{
"https://go.dev/",
"https://golang.org/",
"https://google.com/",
}
codes := slices.MapAsync(
urls, 0,
func(url string) int {
return lambdas.Must(http.Get(url)).StatusCode
},
)
```## ðĻ Usage
Genesis contains the following packages:
+ [ð slices](https://pkg.go.dev/github.com/life4/genesis/slices): generic functions for slices (`[]T`).
+ [ðš maps](https://pkg.go.dev/github.com/life4/genesis/maps): generic functions for maps (`map[K]V`).
+ [ðš channels](https://pkg.go.dev/github.com/life4/genesis/channels): generic function for channels (`chan T`).
+ [âïļ sets](https://pkg.go.dev/github.com/life4/genesis/sets): generic function for sets (`map[T]struct{}`).
+ [ð lambdas](https://pkg.go.dev/github.com/life4/genesis/lambdas): helper generic functions to work with `slices.Map` and similar.See [ð DOCUMENTATION](https://pkg.go.dev/github.com/life4/genesis) for more info.