Closed juhp closed 3 years ago
The second one seems redundant - it's easier to do listToMaybe over the first, or whatever is the right policy to reduce many files down to one.
For filesWithExtension
, what's the benefit over just doing the listFiles
and a filter? My concern is you often want to list files directly, with recursion, and with recursion avoiding .
prefixed directories or similar. By the time you have three variants it starts to explode badly in terms of complexity.
This an implementation of filesWithExtension:
filesWithExtension :: FilePath -> String -> IO [FilePath]
filesWithExtension dir ext =
filter (ext `isExtensionOf`) <$> listFiles dir
I admit it looks pretty straightforward (specially when one remembers to use isExtensionOf).
Maybe listFilesWithExtension
would be a better name.
I see your point, though I find myself using filesWithExtension (and less often fileWithExtension) in various projects: it is a bit less typing. :-)
Yeah, I think I'll close this for now, and not add it. But if in 6 months time or so you've needed to use that one a lot, but not any of the other variations with isExtensionOf, it might be worth considering.
I would like to suggest adding a couple of small functions to System.Directory.Extra:
How does that sound? If it is okay I am happy to open a PR for it.