you could perhaps optimize it to leverage the "tail-recurssive" optimization by doing something like this btw:
nthElementHelper : List a -> Int -> Result String a
nthElementHelper list n =
case (n, list) of
(_, ) ->
Err ("List too short by " ++ String.fromInt (n+1) ++ pluralize n "element" "elements")
(0, x :: _) ->
(nth, _ :: rest) ->
nthElementHelper rest (nth-1)
although come to think of it you're already doing "tail-recurssion"
yeah, I'm already doing that
I still prefer the case of on a tuple than a case of with some if then else branching inside but that's personal taste :)
if then else
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.