Code Monkey home page Code Monkey logo

genesis's Introduction

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.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.

genesis's People

Contributors

calvinbrown085 avatar dwurf avatar jamiri avatar kuchaguangjie avatar malisetti avatar nvcexploder avatar orsinium avatar yuphing-ong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.