A hands-on approach for getting started with Go generics.

Go Generics the Hard Way

This repository is a hands-on approach for getting started with Go generics:

  1. Prerequisites: how to install the prerequisites required to run the examples in this repository
  2. Hello world: a simple example using generics
  3. Delving deeper: looking at a binary compiled from generic code
  4. Benchmarks: basic benchmarks for common patterns using generics
  5. Lessons learned: various lessons learned while exploring generics
  6. In the wild: a living list of projects/patches in the wild using generics
Owner
Andrew Kutz
A father, husband, friend, son, and VMware engineer.
Andrew Kutz
Comments
  • Fix a misleading point in the guide with generic type aliases for functions

    Fix a misleading point in the guide with generic type aliases for functions

    There's nothing really blocking type aliases for functions for being generic themselves, and the alternative (the right way, probably) to do this was never presented in the guide.

    I've fixed 03-getting-started/-9multiple-generic-types.md, but not the rest. You have permission to edit this PR, so feel free to take over from here!

  • Inconsistent syntax?

    Inconsistent syntax?

    As a middle aged hobby coder just starting out with Go I appreciate the simple and straight forward syntax (I’m middle management by day .. and I get the tingling feeling there’s a joke in there somewhere😄). I also enjoy to read the (so far) consistent reasoning of the maintainers for choices made.

    Do you have any idea why this (https://github.com/akutz/go-generics-the-hard-way/blob/490784b7d7c082ea84ddeadefcb02c9b03ff7a5a/03-getting-started/03-constraints.md) logical OR in the generic constraints wasn’t two pipes too? Or is the subtle difference that this generic constraint statement doesn’t actually “result” in a Boolean value or something? Something like why variable assignment and function parameters (signature) have the type the other way around.

    I love stuff like this, partly, I’m sure, because if it makes logical sense it sticks too. Not really an issue with this repo of course (which was timely, complete and well thought out!).

  • function types cannot be generic?

    function types cannot be generic?

    I am reading this chapter: https://github.com/akutz/go-generics-the-hard-way/blob/main/03-getting-started/09-multiple-generic-types.md

    This chapter mentioned that function types cannot be generic. But why is it designed like this? The reason I can think of is that go language is worried about generic nesting, which affects the compilation speed? Or is there another reason

  • Update FAQ

    Update FAQ

    Thank you for your great hands-on!

    I think we can update FAQ about “How are you using generics in the Go playground?”. On the Go playground, we can select runtime environment the "release" or the "dev branch" now. Therefore we can run codes with generics on the Go playground.

    An example link is below: https://go.dev/play/p/kg938K7hORf?v=gotip image

  • Fix other typos in multiple generic types section

    Fix other typos in multiple generic types section

    The PR fixes the typo constriant -> constraint in Multiple generic types section under Getting Started. Besides, it removes a trailing whitespace that I wrongly added in #21 :sweat_smile:

  • fix(documentation)

    fix(documentation)

    Hej Andrew, First of all, thanks for creating this beautiful learning material for everyone.

    I just recognized that the example code needs a fix. You referred to the directory 04-benchmark, but it is actually 06-benchmark.

    Cheers!

  • Reword expression in `06-careful-constructors`?

    Reword expression in `06-careful-constructors`?

    Would you agree that this should be reworded from address to a ... to pointer to a ...? I was expecting to see the address when reading this line whereas the code example and point you make is about a pointer type.

    https://github.com/akutz/go-generics-the-hard-way/blob/8b47aceab58ae85045944232756dc30f0080dfda/04-getting-going/06-careful-constructors.md#L185

Calling functions by name and getting outputs by using reflect package.

Invoker A library to call (invoke) functions by taking names and sample inputs of those functions as parameters. And returns the types and values of o

Dec 20, 2021
Getting into Golang 1.18

Go 1.18 New features of Golang 1.18 with tutorial and examples. In this repository I introduce new features of Golang version 1.18 with their examples

Aug 28, 2022
Code Generation for Functional Programming, Concurrency and Generics in Golang

goderive goderive derives mundane golang functions that you do not want to maintain and keeps them up to date. It does this by parsing your go code fo

Dec 25, 2022
Experiments with Go generics

generics Quick experiments with Go generics algebra, a generic square root function for float, complex and and rational. future, a concurrent cache ("

Dec 31, 2022
Example code for Go generics

go-generics-example Example code for Go generics. Usage $ go build -gcflags=-G=3 Requirements Go 1.17 or later Advertise Go 言語にやってくる Generics は我々に何をも

Dec 30, 2022
Collection of unusual generics usecases in Go

Unusual Generics Type parameters or Generics in Go designed to reduce boilerplate for container data types like lists, graphs, etc. and functions like

Dec 14, 2022
Package truthy provides truthy condition testing with Go generics
Package truthy provides truthy condition testing with Go generics

Truthy Truthy is a package which uses generics (Go 1.18+) to create useful boolean tests and helper functions. Examples // truthy.Value returns the tr

Nov 11, 2022
Go Library for Competitive Programming with Generics

Go Library for Competitive Programming with Generics Go used to be a difficult language to use for competitive programming. However, with the introduc

Dec 21, 2022
Extended library functions using generics in Go.

Just few extended standard library functions for Golang using generics.

Dec 16, 2021
A library that provides Go Generics friendly "optional" features.

go-optional A library that provides Go Generics friendly "optional" features. Synopsis some := optional.Some[int](123) fmt.Printf("%v\n", some.IsSome(

Dec 20, 2022
experimental promises in go1.18 with generics

async go a prototype of "promises" in go1.18. note: this is just an experiment used to test alternate patterns for dealing with asynchronous code in g

Dec 23, 2022
Go 1.18 generics use cases and examples

Go 1.18 generics use cases What are generics? See Type Parameters Proposal. How to run the examples? As of today, gotip is the simplest way to run the

Jan 10, 2022
Functional tools in Go 1.18 using newly introduced generics

functools functools is a simple Go library that brings you your favourite functi

Dec 5, 2022
Experimenting with golang generics to implement functional favorites like filter, map, && reduce.

funcy Experimenting with golang generics to implement functional favorites like filter, map, && reduce. 2021-12 To run the tests, you need to install

Dec 29, 2021
A collection of functional operators for golang with generics

fn fn is a collection of go functional operators with generics Getting Started P

Jul 8, 2022
Benchmarks to compare Go Generics

This is a collection of various sorts implemnted both as []int only and as const

Dec 8, 2022
Utility library that uses Go generics mechanism

golang-generics-util Utility library that explores Go generics (1.18) xsync Sync

Dec 11, 2022
CDN-like in-memory cache with shielding, and Go 1.18 Generics

cache CDN-like, middleware memory cache for Go applications with integrated shielding and Go 1.18 Generics. Usage package main import ( "context" "

Apr 26, 2022
Go 1.18 generics based slice and sorts.

genfuncs import "github.com/nwillc/genfuncs" Package genfuncs implements various functions utilizing Go's Generics to help avoid writing boilerplate c

Jan 2, 2023