August 18, 2022

Generics in Golang

Why generics are so important and why they can save you tons of time. 
Let's try to figure it out.
Start with a simple example: 
func sumOfSome(input int64) int64 {
	var sum int64
	for _, v := range input {
		sum += v
	}
	return sum
}

But what to do if we need not only int64?
In this case, generics will help us.
type Number interface {
	float64 | int64 | int
}


func sumOfSome[T Number](input []T) T {
	var sum T
	for _, v := range input {
		sum += v
	}
	return sum
}
First of all we need create an interface with all types (float64, int64, int) which we whant to sum.

August 9, 2022

First post

Hi, I want to introduce to you a new blog about Golang. Inside the blog, you find exciting articles about Golang and best practices for using Golang. We also have a plan to release some exciting tools written on Golang.