genesis

package module
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 4 Imported by: 0

README ΒΆ

Genesis

Generic functions for Go. Bringing the beauty of functional programming in Go 1.18+.

😎 Features:

  • πŸ› οΈ Over 130 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.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

go get github.com/life4/genesis

πŸ‘€ Examples

Find the minimal value in a slice of ints:

lambdas.Must(slices.Min([]int{42, 7, 13})) == 7

Double values in a slice of ints:

slices.Map([]int{4, 8, 15}, func(el int) int { return el * 2 })

Concurrently check status codes for multiple URLs:

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:

See πŸ“„ DOCUMENTATION for more info.

Documentation ΒΆ

Overview ΒΆ

Package genesis provides generic functions for collections.

Directories ΒΆ

Path Synopsis
Package channels provides generic functions for channels.
Package channels provides generic functions for channels.
Package constraints defines a set of useful constraints to be used with type parameters.
Package constraints defines a set of useful constraints to be used with type parameters.
Package lambdas provides helper generic functions.
Package lambdas provides helper generic functions.
Package maps provides generic functions for maps.
Package maps provides generic functions for maps.
Package slices provides generic functions for slices.
Package slices provides generic functions for slices.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL