Skip to content

Commit df624fe

Browse files
committed
start using range-over-func
It so happens that Environ.Each already conforms to iter.Seq2.
1 parent c9f18cd commit df624fe

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

expand/param.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,10 @@ func (cfg *Config) varInd(vr Variable, idx syntax.ArithmExpr) (string, error) {
415415

416416
func (cfg *Config) namesByPrefix(prefix string) []string {
417417
var names []string
418-
cfg.Env.Each(func(name string, vr Variable) bool {
418+
for name := range cfg.Env.Each {
419419
if strings.HasPrefix(name, prefix) {
420420
names = append(names, name)
421421
}
422-
return true
423-
})
422+
}
424423
return names
425424
}

interp/api.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,7 @@ func (r *Runner) Run(ctx context.Context, node syntax.Node) error {
810810
r.setErr(NewExitStatus(uint8(r.exit)))
811811
}
812812
if r.Vars != nil {
813-
r.writeEnv.Each(func(name string, vr expand.Variable) bool {
814-
r.Vars[name] = vr
815-
return true
816-
})
813+
maps.Insert(r.Vars, r.writeEnv.Each)
817814
}
818815
return r.err
819816
}

interp/vars.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (o *overlayEnviron) Each(f func(name string, vr expand.Variable) bool) {
7676

7777
func execEnv(env expand.Environ) []string {
7878
list := make([]string, 0, 64)
79-
env.Each(func(name string, vr expand.Variable) bool {
79+
for name, vr := range env.Each {
8080
if !vr.IsSet() {
8181
// If a variable is set globally but unset in the
8282
// runner, we need to ensure it's not part of the final
@@ -92,8 +92,7 @@ func execEnv(env expand.Environ) []string {
9292
if vr.Exported && vr.Kind == expand.String {
9393
list = append(list, name+"="+vr.String())
9494
}
95-
return true
96-
})
95+
}
9796
return list
9897
}
9998

0 commit comments

Comments
 (0)