From c6b49897c934335503ed61ef3e92a55e12440ff0 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Tue, 16 Jan 2024 15:16:59 +0000 Subject: [PATCH] Slightly clearer --- exercises/practice/wordy/.meta/example.gleam | 44 ++++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/exercises/practice/wordy/.meta/example.gleam b/exercises/practice/wordy/.meta/example.gleam index c17c682f2..b1cb30d50 100644 --- a/exercises/practice/wordy/.meta/example.gleam +++ b/exercises/practice/wordy/.meta/example.gleam @@ -45,28 +45,28 @@ fn tokenize(question: String) -> Result(List(Token), Error) { } fn evaluate(tokens: List(Token)) -> Result(Int, Error) { - use [Operand(result)] <- result.then( - list.try_fold(tokens, [], fn( - previous_tokens: List(Token), - current_token: Token, - ) { - case previous_tokens, current_token { - [], Operand(_) -> Ok([current_token]) - - [Operand(_)], Operator(_) -> Ok([current_token, ..previous_tokens]) - - [Operator(operation), Operand(left_operand)], Operand(right_operand) -> - case operation(left_operand, right_operand) { - Ok(accumulated_result) -> Ok([Operand(accumulated_result)]) - Error(Nil) -> Error(ImpossibleOperation) - } - - _, _ -> Error(SyntaxError) - } - }), - ) - - Ok(result) + list.try_fold(tokens, [], fn( + previous_tokens: List(Token), + current_token: Token, + ) { + case previous_tokens, current_token { + [], Operand(_) -> Ok([current_token]) + + [Operand(_)], Operator(_) -> Ok([current_token, ..previous_tokens]) + + [Operator(operation), Operand(left_operand)], Operand(right_operand) -> + case operation(left_operand, right_operand) { + Ok(accumulated_result) -> Ok([Operand(accumulated_result)]) + Error(Nil) -> Error(ImpossibleOperation) + } + + _, _ -> Error(SyntaxError) + } + }) + |> result.map(fn(result) { + let assert [Operand(result)] = result + result + }) } fn parse_tokens(chunks: List(String)) -> Result(List(Token), Error) {