Sobes.tech
Senior

Let's assume the task is on Go version 1.18. What will change in the program's behavior?

sobes.tech AI

Answer from AI

Go 1.18 is a version in which support for generics was officially added. This is a key change that affects program behavior, allowing for writing more universal and reusable code without losing type safety.

For example, before Go 1.18, creating a function that works with different types required using interfaces or duplicating code. With generics, you can write a function that accepts a type parameter:

func Map[T any, R any](items []T, f func(T) R) []R {
    result := make([]R, len(items))
    for i, v := range items {
        result[i] = f(v)
    }
    return result
}

Thus, the behavior of the program changes in terms of capabilities: now you can use generics to increase flexibility and readability of the code, which was previously impossible or inconvenient.