Skip to content

Instantly share code, notes, and snippets.

View faiface's full-sized avatar

Michal Štrba faiface

View GitHub Profile
package main
import (
"fmt"
"math"
"os"
"time"
"golang.org/x/image/colornames"
package main
import (
"math"
"os"
"time"
"github.com/faiface/beep"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
package main
import (
"os"
"time"
"github.com/faiface/beep"
"github.com/faiface/beep/speaker"
"github.com/faiface/beep/wav"
)
package main
import (
"os"
"time"
"github.com/faiface/beep"
"github.com/faiface/beep/speaker"
"github.com/faiface/beep/wav"
)
package main
import (
"fmt"
"math"
"os"
"time"
"github.com/faiface/beep"
"github.com/faiface/beep/effects"

Ideas on generics in Go

As we all know, Go 2 is on its way and despite the hesitations, it's clear that without generics, it would end up being a disappointment. And although we are still gathering real-life use-cases, or experience reports, there's nothing bad about starting to think about how generics in Go could look like. I've come up with a few ideas which I'd love to share. So, here we go!

What's already achievable?

Now, Go 1 has no generics, but has interfaces. Interfaces (sometime accompanied by reflection)

package main
import (
"math"
"time"
"github.com/faiface/pixel"
"github.com/faiface/pixel/audio"
"github.com/faiface/pixel/audio/speaker"
"github.com/faiface/pixel/pixelgl"
package main
import (
"math"
"time"
"github.com/faiface/pixel"
"github.com/faiface/pixel/audio"
"github.com/faiface/pixel/audio/speaker"
"github.com/faiface/pixel/pixelgl"
package main
import (
"math"
"time"
"github.com/faiface/pixel/audio"
"github.com/faiface/pixel/audio/speaker"
)
@faiface
faiface / .go
Last active July 7, 2017 11:31
package main
import (
"math"
"time"
"github.com/faiface/pixel"
"github.com/faiface/pixel/audio"
"github.com/faiface/pixel/audio/speaker"
"github.com/faiface/pixel/pixelgl"