Hi there!
I've just begun my journey with Roc .
I'm attempting to create a program that lists files in a directory and extracts some data from each file. I have a function processFile: Path -> Task Str err
and from Dir.list, I receive Task (List Path)
. However, I don't know how to combine them do create a(Set Str)
.
I tried to map the list and created Task List (Task Str)
but I'm not sure if it is a good approach.
Please, give me some advice
You can use either Task.await
or Task.loop
1sec I'll grab an example
Here is an example from roc-wasm4 using Task.loop
getRandomFruit : Snake -> Task Fruit []
getRandomFruit = \{ head, body } ->
Task.loop {} \{} ->
x <- W4.randBetween { start: 0, before: 20 } |> Task.await
y <- W4.randBetween { start: 0, before: 20 } |> Task.await
fruit = { x, y }
if fruit == head || List.contains body fruit then
Step {} |> Task.ok
else
Done fruit |> Task.ok
Or this may be closer to what you need
drawSnakeBody : Snake -> Task {} []
drawSnakeBody = \snake ->
List.walk snake.body (Task.ok {}) \task, part ->
{} <- task |> Task.await
W4.rect { x: (part.x * 8), y: (part.y * 8), width: 8, height: 8 }
Here you could pass in your List Path
instead of Snake
and walk the list using Task.await
So I imagine you want to create a function like processFiles : List Path -> Task (List Str) [YourErrorsTypes]
It worked with Task.loop,
Thank you!
Szymon Kolorz has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC