Hi all,
I've been trying to wrap my head around the ? suffix.
As far as I can tell, it unwraps the result and "returns early" in the error case... is that right?
How would I write this code from the tutorial with Result.try
rather than ?
?
getLetter : Str -> Result Str [OutOfBounds, InvalidNumStr]
getLetter = \indexStr ->
index = Str.toU64? indexStr
List.get ["a", "b", "c", "d"] index
I can't quite figure it out. I tried something like this, but it doesn't really map onto the assignment to index
above:
getLetter : Str -> Result Str [OutOfBounds, InvalidNumStr]
getLetter = \indexStr ->
Result.try (Str.toU64 indexStr) \index ->
List.get ["a", "b", "c", "d"] index
In current roc, I'm pretty sure those two functions are 100% equivalent
The first desugars into the second
Oh I see! Thank you :man_bowing:
Nathan Kramer has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC