Skip to content
Typesafe concurrent generic functions for Go
Go Python
Branch: master
Clone or download
Latest commit d2ed89b Nov 11, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
generate generate everything for rune and error types Nov 8, 2019
implementation +travisci script Nov 11, 2019
.gitignore fix async tests generating Sep 22, 2019
.travis.yml fix tests run Nov 11, 2019
LICENSE Create LICENSE Sep 13, 2019
README.md +travis badge Nov 11, 2019
generated.go +travisci script Nov 11, 2019
generated_test.go generate everything for rune and error types Nov 8, 2019
genesis_test.go
go.mod +travisci script Nov 11, 2019
go.sum +travisci script Nov 11, 2019
gopher.png +gopher Oct 31, 2019
requirements.txt update docs Sep 24, 2019

README.md

Genesis

Build Status

Missed golang generic stdlib for slices and channels.

Some functions:

  • Filter, Map, Reduce.
  • Min, Max, Sum.
  • Permutations, Product.
  • Any, All.
  • Contains, Find.
  • Shuffle, Sort.
  • Range, Count, Cycle.

And much more.

Features:

  • Typesafe.
  • Sync and async versions.
  • For slices and channels.
  • Pre-generated for all built-in types.
go get github.com/life4/genesis

Examples

Find minimal value in a slice of ints:

s := []int{42, 7, 13}
min := genesis.SliceInt{s}.Min()

Double values in a slice of ints:

s := []int{4, 8, 15, 16, 23, 42}
double := func(el int) int { return el * 2 }
doubled := genesis.SliceInt{s}.MapInt(double)

See docs to dive deeper.

Custom types

Genesis contains pre-generated code for common built-in types. So, in most cases you can just use it. However, if you want to use genesis for custom types, things become a little bit more complicated. The first option is to use an empty interface. For example:

type UserId int
ids := []UserId{1, 2, 3, 4, 5}
// https://github.com/golang/go/wiki/InterfaceSlice
idsInterface := make([]interface{}, len(ids), len(ids))
for i := range ids {
	idsInterface[i] = ids[i]
}
index := genesis.SliceInterface{idsInterface}.FindIndex(
	func(el interface{}) bool { return el.(UserId) == 3 },
)
fmt.Println(index)
// Output: 2

Another option is to generate genesis code for your own type.

Generation

Install requirements

python3 -m pip install --user -r requirements.txt

Re-generate everything for built-in types:

python3 -m generate

Generate a new package with given types:

python3 -m generate

>>> DOCUMENTATION <<<

All code is autogenerated, so go doc output is quite messy. Hence we have docs folder with a nice generated documentation for everything. Enjoy.

You can’t perform that action at this time.