Stream: ideas

Topic: basic-cli Path isDir


view this post on Zulip Anton (Dec 27 2023 at 15:58):

I propose the addition of the following functions to basic-cli Path:

view this post on Zulip Kevin Gillette (Dec 27 2023 at 16:57):

Why 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.

view this post on Zulip Anton (Dec 27 2023 at 16:59):

I was mainly thinking about easy filtering with keepIf/dropIf

view this post on Zulip Anton (Dec 27 2023 at 17:01):

The discoverability of type is also not very good

view this post on Zulip Kevin Gillette (Dec 27 2023 at 17:01):

hmmmm. well then let's just add currying and (==) :stuck_out_tongue_closed_eyes:

view this post on Zulip Kevin Gillette (Dec 27 2023 at 17:04):

I guess you could also have:

isType : [IsFile, IsDir, IsSymlink] -> (Str -> Bool)

view this post on Zulip Kevin Gillette (Dec 27 2023 at 17:05):

filenames |> List.keepIf (Path.isType IsDir)

view this post on Zulip Agus Zubiaga (Dec 27 2023 at 17:05):

Or just Path.is Dir maybe?

view this post on Zulip Kevin Gillette (Dec 27 2023 at 17:05):

is is a keyword?

view this post on Zulip Agus Zubiaga (Dec 27 2023 at 17:06):

Ah, right :big_smile:

view this post on Zulip Kevin Gillette (Dec 27 2023 at 17:18):

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?

view this post on Zulip Kevin Gillette (Dec 27 2023 at 17:24):

Also, how would we want to handle other file types (which aren't necessarily special), such as sockets, devices, named pipes, etc?

  1. Directly enumerating the extra types known to supported platforms in the Path.type result and optionally making it return an explicitly open tag union?
  2. IsSpecial with some nested tag parameter?
  3. IsSpecial without the tag parameter, but with a Path.specialType companion function?
  4. Just considering special files to be regular files?

view this post on Zulip Brendan Hansknecht (Dec 27 2023 at 17:57):

Kevin Gillette said:

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?

Currently definitely not. Long term, hopefully.

view this post on Zulip Anton (Dec 27 2023 at 18:19):

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