Genesis
All generic functions for Go you ever need!
Generic functions for Go. Bringing the beauty of functional programming in Go 1.18+. The project is written primarily in Go, distributed under the MIT License license, first published in 2019. Key topics include: elixir, enum, erlang, fp, functional-programming.
Latest release: v1.10.3
April 23, 2024View Changelog โ
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 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.Shrinkis 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, andReducefor data processing on steroids.FilterAsync,MapAsync, andReduceAsyncfor making your code fast and concurrent with a single line of code.GrowandShrinkfor reducing memory allocations.PermutationsandProductfor simple iterations.ShuffleandSortfor randomization.AnyandAllfor simple flow control.Range,Count, andCyclefor generating sequences.
And much more.
๐พ Installation
bashgo get github.com/life4/genesis
๐ Examples
Find the minimal value in a slice of ints:
golambdas.Must(slices.Min([]int{42, 7, 13})) == 7
Double values in a slice of ints:
goslices.Map([]int{4, 8, 15}, func(el int) int { return el * 2 })
Concurrently check status codes for multiple URLs:
gourls := []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: generic functions for slices (
[]T). - ๐บ maps: generic functions for maps (
map[K]V). - ๐บ channels: generic function for channels (
chan T). - โ๏ธ sets: generic function for sets (
map[T]struct{}). - ๐ lambdas: helper generic functions to work with
slices.Mapand similar.
See ๐ DOCUMENTATION for more info.
Contributors
Showing top 9 contributors by commit count.
This article is auto-generated from life4/genesis via the GitHub API.Last fetched: 6/28/2026
