From af030b9e7b4a8a8e7a71af2bc5020a3314d08c5d Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Sun, 8 Jan 2017 11:04:56 +0100 Subject: [PATCH] Try to make visits simpler --- Lint.elm | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/Lint.elm b/Lint.elm index 868cb493..4d35c44b 100644 --- a/Lint.elm +++ b/Lint.elm @@ -93,24 +93,20 @@ statementToVisitors node = [] +visitAndAccumulate : LintRule context -> Visitor context -> ( List Error, context ) -> ( List Error, context ) +visitAndAccumulate rule visitor ( errors, ctx ) = + visitor rule ctx + |> Tuple.mapFirst (\errors_ -> errors ++ errors_) + + lintWithVisitors : List (Visitor context) -> LintRule context -> List Error lintWithVisitors visitors rule = - let - ( errors, _ ) = - List.foldl - (\visitor ( errors, ctx ) -> - let - ( errors_, ctx_ ) = - visitor rule ctx - in - ( errors ++ errors_, ctx_ ) - ) - ( [], rule.context ) - visitors - in - errors + visitors + |> List.foldl (visitAndAccumulate rule) ( [], rule.context ) + |> Tuple.first lint : List Statement -> LintRule context -> List Error lint statements = - lintWithVisitors (List.concatMap statementToVisitors statements) + List.concatMap statementToVisitors statements + |> lintWithVisitors