I've been working with Golang for a while now and I've come to love the generics they introduced. Making stuff type-safe is a bit of a hassle, but it pays off greatly.

One thing I had yet to consider though, is that functions are also a type, so that those could be made generic too.

func DoThing[F func(string) | func(int)](callback F) {...}

Now you can deliver both function types and I can differentiate them using a type switch.

Weird that sometimes my brain doesn't make that connection immediately...

  • 3
    I mean they are types even on C

    No seriously, lookup std qsort documentation
Add Comment