I propose the addition of the following functions to basic-cli Path:
isDir : Path -> BoolisFile: Path -> BoolisSymLink: Path -> Booltype: Path -> [IsFile, IsDir, IsSymLink] I used the Is prefix to prevent confusion/collision with the modules File and DirWhy not just stick with type, given the preference towards tags over bools?
if Path.isDir path then
is equivalent to:
if Path.type path == IsDir then
both require an else, both are pretty concise, but one also lends itself to pattern matching.
I was mainly thinking about easy filtering with keepIf/dropIf
The discoverability of type is also not very good
hmmmm. well then let's just add currying and (==) :stuck_out_tongue_closed_eyes:
I guess you could also have:
isType : [IsFile, IsDir, IsSymlink] -> (Str -> Bool)
filenames |> List.keepIf (Path.isType IsDir)
Or just Path.is Dir maybe?
is is a keyword?
Ah, right :big_smile:
In any case, I'm guessing that if we do:
Dir.list dirname
|> Result.withDefault []
|> List.keepIf Path.isDir
Then that'll still produce an intermediary list of 1000 elements even if there is just one dir alongside 999 regular files?
iow because a platform implements Dir.list there isn't any way for Roc to optimize that to inline the list filling with the list pruning into something that just conditionally fills the list?
If Dir.list were just pure Roc implemented atop something like a Dir.walk implemented by the platform, would Roc then be able to optimize the above pipeline to avoid a large temporary list?
Also, how would we want to handle other file types (which aren't necessarily special), such as sockets, devices, named pipes, etc?
Path.type result and optionally making it return an explicitly open tag union?IsSpecial with some nested tag parameter?IsSpecial without the tag parameter, but with a Path.specialType companion function?Kevin Gillette said:
If
Dir.listwere just pure Roc implemented atop something like aDir.walkimplemented by the platform, would Roc then be able to optimize the above pipeline to avoid a large temporary list?
Currently definitely not. Long term, hopefully.
Also, how would we want to handle other file types
Rust has three types, so that seems pretty safe.
Just considering special files to be regular files?
That makes sense to me, Linux has lots of special files but they are still just files.
Last updated: Jun 16 2026 at 16:19 UTC