Alexey Soshin
Jan 22, 2021

--

Set can be defined almost the same way, but instead of slice, the underlying structure would be map:

type Set[T comparable] struct {

elems map[T]bool

}

Note that I'm using the newest generics syntax: [T comparable]

And not the older syntax from the article: (type T)

--

--

Alexey Soshin
Alexey Soshin

Written by Alexey Soshin

Solutions Architect @Depop, author of “Kotlin Design Patterns and Best Practices” book and “Pragmatic System Design” course

No responses yet