Skip to content

Commit 130b1e6

Browse files
authored
Removes dependence on x/exp/maps (#33)
2 parents 39fc260 + e261d7c commit 130b1e6

14 files changed

Lines changed: 22 additions & 177 deletions

File tree

go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@ module go.ufukty.com/gonfique/v2
22

33
go 1.26
44

5-
require (
6-
golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d
7-
gopkg.in/yaml.v3 v3.0.1
8-
)
5+
require gopkg.in/yaml.v3 v3.0.1

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d h1:0olWaB5pg3+oychR51GUVCEsGkeCU/2JxjBgIo4f3M0=
2-
golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c=
31
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
42
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
53
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

internal/compares/compare.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ package compares
22

33
import (
44
"go/ast"
5+
"maps"
56
"slices"
6-
7-
"golang.org/x/exp/maps"
87
)
98

109
func sort(idts []*ast.Ident) {
@@ -50,14 +49,14 @@ func Compare(a, b any) bool {
5049
}
5150
af := linearizeFieldList(a)
5251
bf := linearizeFieldList(b)
53-
afk := maps.Keys(af)
54-
bfk := maps.Keys(bf)
52+
afk := slices.Collect(maps.Keys(af))
53+
bfk := slices.Collect(maps.Keys(bf))
5554
if len(afk) != len(bfk) {
5655
return false
5756
}
5857
sort(afk)
5958
sort(bfk)
60-
for i := 0; i < len(afk); i++ {
59+
for i := range afk {
6160
if !Compare(afk[i], bfk[i]) || !Compare(af[afk[i]], bf[bfk[i]]) {
6261
return false
6362
}

internal/datas/sortby/by.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ package sortby
33
import (
44
"cmp"
55
"iter"
6+
"maps"
67
"slices"
7-
8-
"golang.org/x/exp/maps"
98
)
109

1110
func Key[K cmp.Ordered, V any](m map[K]V) iter.Seq2[K, V] {
1211
return KeyFunc(m, cmp.Compare)
1312
}
1413

1514
func KeyFunc[K cmp.Ordered, V any](m map[K]V, cmp func(a, b K) int) iter.Seq2[K, V] {
16-
ks := maps.Keys(m)
17-
slices.SortFunc(ks, cmp)
1815
return func(yield func(K, V) bool) {
19-
for _, k := range ks {
16+
for _, k := range slices.SortedFunc(maps.Keys(m), cmp) {
2017
if !yield(k, m[k]) {
2118
return
2219
}

internal/files/coder/write.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"go/printer"
99
"go/token"
1010
"io"
11+
"maps"
1112
"regexp"
1213
"slices"
1314
"strings"
@@ -19,7 +20,6 @@ import (
1920
"go.ufukty.com/gonfique/v2/internal/files/input/encoders"
2021
"go.ufukty.com/gonfique/v2/internal/namings"
2122
"go.ufukty.com/gonfique/v2/internal/version"
22-
"golang.org/x/exp/maps"
2323
)
2424

2525
type Coder struct {
@@ -47,7 +47,7 @@ func uniq[K comparable](ss []K) []K {
4747
for _, s := range ss {
4848
m[s] = nil
4949
}
50-
return maps.Keys(m)
50+
return slices.Collect(maps.Keys(m))
5151
}
5252

5353
func (c Coder) addImports(dst *ast.File) {

internal/paths/declare/agent.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package declare
22

33
import (
44
"go/ast"
5+
"maps"
6+
"slices"
57

68
"go.ufukty.com/gonfique/v2/internal/files/config"
79
"go.ufukty.com/gonfique/v2/internal/paths/mapper/resolve"
8-
"golang.org/x/exp/maps"
910
)
1011

1112
// keeps track of type expression and typename conflicts.
@@ -25,5 +26,5 @@ func New() *Agent {
2526
}
2627

2728
func (a *Agent) Typenames() []config.Typename {
28-
return maps.Keys(a.users)
29+
return slices.Collect(maps.Keys(a.users))
2930
}

internal/paths/declare/conflicts.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"cmp"
55
"fmt"
66
"go/ast"
7+
"maps"
78
"slices"
89

910
"go.ufukty.com/gonfique/v2/internal/compares"
1011
"go.ufukty.com/gonfique/v2/internal/files/config"
1112
"go.ufukty.com/gonfique/v2/internal/paths/mapper/resolve"
12-
"golang.org/x/exp/maps"
1313
)
1414

1515
func groupSchemas(users []resolve.Path, exprs map[resolve.Path]ast.Expr) map[ast.Expr][]resolve.Path {
@@ -94,7 +94,7 @@ func summarize(e ast.Expr) string {
9494
// in sorted order
9595
func format(cs map[config.Typename]map[ast.Expr][]resolve.Path) string {
9696
msg := ""
97-
tns := maps.Keys(cs)
97+
tns := slices.Collect(maps.Keys(cs))
9898
slices.Sort(tns)
9999
for i := 0; i < len(tns); i++ {
100100
heading := ternary(i != len(tns)-1, "├─ ", "╰─ ")
@@ -106,7 +106,7 @@ func format(cs map[config.Typename]map[ast.Expr][]resolve.Path) string {
106106
for t := range users {
107107
summaries[t] = summarize(t)
108108
}
109-
types := maps.Keys(users)
109+
types := slices.Collect(maps.Keys(users))
110110
slices.SortFunc(types, func(a, b ast.Expr) int {
111111
return cmp.Compare(summaries[a], summaries[b])
112112
})

internal/paths/export/auto/autogen_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package auto
33
import (
44
"cmp"
55
"fmt"
6+
"maps"
67
"slices"
78
"strings"
89
"testing"
910

1011
"go.ufukty.com/gonfique/v2/internal/files/config"
1112
"go.ufukty.com/gonfique/v2/internal/paths/mapper/resolve"
12-
"golang.org/x/exp/maps"
1313
)
1414

1515
func bfs(a, b resolve.Path) int {
@@ -31,7 +31,7 @@ func typenames(rps []resolve.Path) (map[resolve.Path]config.Typename, error) {
3131
slices.SortFunc(rps, bfs)
3232
tns := map[resolve.Path]config.Typename{}
3333
for _, rp := range rps {
34-
tn, ok := Typename(rp, maps.Values(tns))
34+
tn, ok := Typename(rp, slices.Collect(maps.Values(tns)))
3535
if !ok {
3636
return nil, fmt.Errorf("could not produce typename for %s", rp)
3737
}
@@ -139,7 +139,7 @@ func TestAutogen(t *testing.T) {
139139

140140
for _, tc := range tcs {
141141
t.Run(tc.testname, func(t *testing.T) {
142-
got, err := typenames(maps.Keys(tc.output))
142+
got, err := typenames(slices.Collect(maps.Keys(tc.output)))
143143
if err != nil {
144144
t.Fatal(fmt.Errorf("act: %w", err))
145145
}

internal/paths/paths.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package paths
33
import (
44
"fmt"
55
"go/ast"
6+
"maps"
67
"slices"
78

89
"go.ufukty.com/gonfique/v2/internal/datas/sortby"
@@ -19,7 +20,6 @@ import (
1920
"go.ufukty.com/gonfique/v2/internal/paths/replace"
2021
"go.ufukty.com/gonfique/v2/internal/transform"
2122
"go.ufukty.com/gonfique/v2/internal/tree/bucket"
22-
"golang.org/x/exp/maps"
2323
)
2424

2525
type products struct {
@@ -31,7 +31,7 @@ func Process(ti *transform.Info, c *config.File, verbose bool) (*products, error
3131
declare := declare.New()
3232
export := export.New([]config.Typename{}) // FIXME:
3333
replace := replace.New()
34-
paths := maps.Keys(c.Rules)
34+
paths := slices.Collect(maps.Keys(c.Rules))
3535

3636
mps, err := mapper.Bfs(ti, c, paths, export)
3737
if err != nil {

internal/testutils/nodestring.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ package testutils
33
import (
44
"fmt"
55
"go/ast"
6+
"maps"
67
"reflect"
78
"slices"
89
"strings"
9-
10-
"golang.org/x/exp/maps"
1110
)
1211

1312
func PrintPathways(v reflect.Value, anc []string) {
@@ -26,7 +25,7 @@ func PrintPathways(v reflect.Value, anc []string) {
2625
for iter.Next() {
2726
m[iter.Key().String()] = iter.Value()
2827
}
29-
ks := maps.Keys(m)
28+
ks := slices.Collect(maps.Keys(m))
3029
slices.Sort(ks)
3130
for _, k := range ks {
3231
PrintPathways(m[k], append(slices.Clone(anc), k))

0 commit comments

Comments
 (0)