Skip to content

Commit 4373094

Browse files
committed
Use internal anonymous function to simplify alogirthms
1 parent 8d52872 commit 4373094

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

readdir.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,21 @@ func (p *Path) ReadDir(filters ...ReadDirFilter) (PathList, error) {
4545
if err != nil {
4646
return nil, err
4747
}
48+
49+
accept := func(p *Path) bool {
50+
for _, filter := range filters {
51+
if !filter(p) {
52+
return false
53+
}
54+
}
55+
return true
56+
}
57+
4858
paths := PathList{}
49-
fileLoop:
5059
for _, info := range infos {
5160
path := p.Join(info.Name())
52-
for _, filter := range filters {
53-
if !filter(path) {
54-
continue fileLoop
55-
}
61+
if !accept(path) {
62+
continue
5663
}
5764
paths.Add(path)
5865
}
@@ -98,18 +105,21 @@ func (p *Path) ReadDirRecursiveFiltered(recursionFilter ReadDirFilter, filters .
98105
if err != nil {
99106
return nil, err
100107
}
101-
paths := PathList{}
102-
for _, info := range infos {
103-
path := p.Join(info.Name())
104108

105-
accept := true
109+
accept := func(p *Path) bool {
106110
for _, filter := range filters {
107-
if !filter(path) {
108-
accept = false
109-
break
111+
if !filter(p) {
112+
return false
110113
}
111114
}
112-
if accept {
115+
return true
116+
}
117+
118+
paths := PathList{}
119+
for _, info := range infos {
120+
path := p.Join(info.Name())
121+
122+
if accept(path) {
113123
paths.Add(path)
114124
}
115125

0 commit comments

Comments
 (0)