diff options
Diffstat (limited to 'internal/oi')
| -rw-r--r-- | internal/oi/oi.go | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/internal/oi/oi.go b/internal/oi/oi.go index 824c0bd..2f1bc1a 100644 --- a/internal/oi/oi.go +++ b/internal/oi/oi.go @@ -49,7 +49,22 @@ func ReadDirCh[T any](dir string, cb func(file os.DirEntry) (T, bool)) (chan T, return ch, nil } -func TraverseDir(dir string, cb func(file os.DirEntry) error) error { +func ReadDir[T any](dir string, cb func(file os.DirEntry) (T, bool)) ([]T, error) { + var results []T + + ch, err := ReadDirCh(dir, cb) + if err != nil { + return results, err + } + + for file := range ch { + results = append(results, file) + } + + return results, nil +} + +func ForeachDirEntry(dir string, cb func(file os.DirEntry) error) error { if err := EnsureDir(dir); err != nil { return err } @@ -69,21 +84,6 @@ func TraverseDir(dir string, cb func(file os.DirEntry) error) error { return errors.Join(errs...) } -func ReadDir[T any](dir string, cb func(file os.DirEntry) (T, bool)) ([]T, error) { - var results []T - - ch, err := ReadDirCh(dir, cb) - if err != nil { - return results, err - } - - for file := range ch { - results = append(results, file) - } - - return results, nil -} - func ReadDirRandom[T any](dir string, cb func(file os.DirEntry) (T, bool)) (T, error) { results, err := ReadDir(dir, cb) |
