Loops to Folds - rewriting imperative loops in Elm