Skip to content

Commit

Permalink
fix: sort object *inside* tags too
Browse files Browse the repository at this point in the history
Signed-off-by: Rachel Powers <[email protected]>
  • Loading branch information
Ryex committed Oct 24, 2024
1 parent 2831c99 commit 65df801
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/structures/set.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package structures

import (
"cmp"
"encoding/json"
"fmt"
"iter"
"maps"
"slices"
)

type Set[T comparable] struct {
type Set[T cmp.Ordered] struct {
data map[T]struct{}
}

func NewSet[T comparable]() *Set[T] {
func NewSet[T cmp.Ordered]() *Set[T] {
s := &Set[T]{}
s.data = make(map[T]struct{})
return s
}

func SetFrom[T comparable](from []T) *Set[T] {
func SetFrom[T cmp.Ordered](from []T) *Set[T] {
s := NewSet[T]()
s.AddM(from...)
return s
Expand Down Expand Up @@ -135,7 +138,7 @@ func (s *Set[T]) UnmarshalJSON(bytes []byte) error {
}

func (s *Set[T]) MarshalJSON() ([]byte, error) {
data := s.AsSlice()
data := slices.Sorted(maps.Keys(s.data))
return json.Marshal(data)
}

Expand Down

0 comments on commit 65df801

Please sign in to comment.