Effect.iterate and Effect.loop: Understanding Effectful Operations in a Directory Search

Hi there, I often use Effect.iterate and Effect.loop and was wondering why only the body is effectful. For instance, I have written a snippet that, starting from the current directory, goes up until it reaches the user's directory or finds a specific file. Ideally, the way I would like to write it is:
const resultPath = Effect.iterate(
    startPath,
    {
        while: specificFileNotInDir,
        body: goUpOneLevel
    }
)

where specificFileNotInDir and goUpOneLevel are effectful functions.
But this is currently not possible because the while callback expects a boolean, not an Effect<R,E,boolean>.
Of course, I can manage to do like so:
const resultPath = Effect.iterate(
    {path:startPath, keepSearching:true, first:true},
    {
        while: ({keepSearching})=>keepSearching,
        body: ({ path, first }) =>
                Effect.flatMap(
                    first ? Effect.succeed(path) : goUpOneLevel(path),
                    (nextPath)=> pipe(
                        nextPath,
                        specificFileNotInDir,
                        Effect.map(
                            (keepSearching) => ({
                                path:nextPath,
                                keepSearching,
                                first:false
                            })
                        )
                    )
            )
        
        }
)

But it adds a lot of complexity for the same result. Do you think there would be a way to add an effectful while callback to Effect.iterate and effectful while and step callbacks to Effect.loop? For simplicity's sake, I skipped the condition relative to reaching the user's directory above.
Or maybe there is another function I could use to achieve this?
Was this page helpful?