Represent and transform data safely
15 articles
-
Represent and transform data safely
Remove Duplicate Values from a Go Slice Without Losing First-Seen Order
Use a map-backed pass to keep the first occurrence of each comparable value, an equality function for other values, or sorting and compacting when order can change.
-
Represent and transform data safely
Find an Element in a Go Slice with `slices.Index` or a Loop
Use `slices.Index` for the first matching position, `slices.Contains` for membership, and a loop when a predicate defines the match.
-
Represent and transform data safely
Sum Values in a Go Slice with a Loop or `slices.Reduce`
Use a range loop for a straightforward `[]int` total, or a third-party reducer when the callback makes a more varied calculation easier to express.
-
Represent and transform data safely
Find the Maximum in a Go Slice Without Sorting It
Find the largest value in a Go slice with a one-pass loop or slices.Max, while making empty-input behavior explicit.
-
Represent and transform data safely
Sort a Go Slice Descending with sort.Slice or sort.Interface
Use sort.Slice for a one-off descending comparison, or define sort.Interface when the ordering is worth reusing.
-
Represent and transform data safely
Go Interface to String: When to Assert and When to Format
Use a type assertion to retrieve a string held by an interface, or fmt to produce a textual representation of another value.
-
Represent and transform data safely
Go Interfaces and Pointer Receivers: Does the Struct or Its Pointer Implement It?
If an interface requires a pointer-receiver method, pass a pointer to the struct: the struct value itself does not satisfy that interface.
-
Represent and transform data safely
How to Merge Two Maps in Go
Merge Go maps with a loop or maps.Copy, choose whether to mutate an input, and understand when generics or mergo better fit the job.
-
Represent and transform data safely
How to Use Sets in Go with mapset and Map-Based Sets
Use map[T]struct{} for lightweight membership checks, or mapset v2 when you need typed set operations and a concurrency-oriented implementation.
-
Represent and transform data safely
How to Clone a Map in Go Without Sharing the Underlying Values
Learn when maps.Clone is enough, why reference-valued entries still alias, and how to write a true deep copy for maps containing slices.










