I am getting this error, which makes sense, but I would like to use the index as a string. The point of the code is to replace the word “one” in a string with the number 1. This is done by walking through each word “one”, “two”, etc. (I’m trying to do learn Roc with advent of code, I’m used to imperative languages mostly :))
This 3rd argument to walkWithIndex has an unexpected type:
24│ List.walkWithIndex numDigit unproccesedInput Str.replaceEach
^^^^^^^^^^^^^^^
This replaceEach value is a:
Str, Str, Str -> Str
But walkWithIndex needs its 3rd argument to be:
Str, Str, Nat -> Str
Just add a wrapping lambda that converts to a Str. \state, elem, index -> Str.replaceEach state elem (Num.toStr index)
Last updated: Jul 06 2025 at 12:14 UTC