Skip to content

Commit cd07693

Browse files
committed
OrFilter and AndFilter now accepts an arbitrary amount of filters
1 parent 02a3ced commit cd07693

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

readdir.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,29 @@ func FilterOutPrefixes(rejectedPrefixes ...string) ReadDirFilter {
206206
}
207207
}
208208

209-
// OrFilter creates a ReadDirFilter that accepts all items that are accepted by x or by y
210-
func OrFilter(x, y ReadDirFilter) ReadDirFilter {
209+
// OrFilter creates a ReadDirFilter that accepts all items that are accepted
210+
// by any (at least one) of the given filters
211+
func OrFilter(filters ...ReadDirFilter) ReadDirFilter {
211212
return func(path *Path) bool {
212-
return x(path) || y(path)
213+
for _, f := range filters {
214+
if f(path) {
215+
return true
216+
}
217+
}
218+
return false
213219
}
214220
}
215221

216-
// AndFilter creates a ReadDirFilter that accepts all items that are accepted by both x and y
217-
func AndFilter(x, y ReadDirFilter) ReadDirFilter {
222+
// AndFilter creates a ReadDirFilter that accepts all items that are accepted
223+
// by all the given filters
224+
func AndFilter(filters ...ReadDirFilter) ReadDirFilter {
218225
return func(path *Path) bool {
219-
return x(path) && y(path)
226+
for _, f := range filters {
227+
if !f(path) {
228+
return false
229+
}
230+
}
231+
return true
220232
}
221233
}
222234

0 commit comments

Comments
 (0)