7 ms·
I was curious about the syntax of this signature: > List.first : List a -> Result a [ListWasEmpty] I found this section of the tutorial useful (and the prece
by pushcx 2y ago
I was curious about the syntax of this signature:
> List.first : List a -> Result a [ListWasEmpty]
I found this section of the tutorial useful (and the preceding example of calling List.get): https://www.roc-lang.org/tutorial#error-handling https://www.roc-lang.org/tutorial#error-handling
The `a` is the type from the `Ok` constructor (similar to Haskell's Left constructor in Either) and the brackets mean "List", not "optional" as in CLI docs, it's a list of types that might be used in the `Err` constructor (similar to Right). So `List.first` either returns `Ok a` or `Err ListWasEmpty`. For a slightly larger example, the tutorial has a `getLetter` that shows two error types.