mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-09-11 16:16:09 +03:00
Add a helper for List.foldl with reversed arguments
This commit is contained in:
parent
472306c292
commit
cb6f0ae746
@ -5544,12 +5544,7 @@ visitExpression expressionRelatedVisitors node errorsAndContext =
|
||||
Expression.LetExpression letBlock ->
|
||||
errorsAndContext
|
||||
|> visitWithListOfVisitors expressionRelatedVisitors.expressionVisitorsOnEnter node
|
||||
|> (\errorsAndContext_ ->
|
||||
List.foldl
|
||||
(visitLetDeclaration expressionRelatedVisitors (Node (Node.range node) letBlock))
|
||||
errorsAndContext_
|
||||
letBlock.declarations
|
||||
)
|
||||
|> ListExtra.foldlSwitched (visitLetDeclaration expressionRelatedVisitors (Node (Node.range node) letBlock)) letBlock.declarations
|
||||
|> visitExpression expressionRelatedVisitors letBlock.expression
|
||||
|> visitWithListOfVisitors expressionRelatedVisitors.expressionVisitorsOnExit node
|
||||
|
||||
@ -5557,18 +5552,13 @@ visitExpression expressionRelatedVisitors node errorsAndContext =
|
||||
errorsAndContext
|
||||
|> visitWithListOfVisitors expressionRelatedVisitors.expressionVisitorsOnEnter node
|
||||
|> visitExpression expressionRelatedVisitors caseBlock.expression
|
||||
|> (\errorsAndContext_ -> List.foldl (visitCaseBranch expressionRelatedVisitors (Node (Node.range node) caseBlock)) errorsAndContext_ caseBlock.cases)
|
||||
|> ListExtra.foldlSwitched (visitCaseBranch expressionRelatedVisitors (Node (Node.range node) caseBlock)) caseBlock.cases
|
||||
|> visitWithListOfVisitors expressionRelatedVisitors.expressionVisitorsOnExit node
|
||||
|
||||
_ ->
|
||||
errorsAndContext
|
||||
|> visitWithListOfVisitors expressionRelatedVisitors.expressionVisitorsOnEnter node
|
||||
|> (\errorsAndContext_ ->
|
||||
List.foldl
|
||||
(visitExpression expressionRelatedVisitors)
|
||||
errorsAndContext_
|
||||
(expressionChildren node)
|
||||
)
|
||||
|> ListExtra.foldlSwitched (visitExpression expressionRelatedVisitors) (expressionChildren node)
|
||||
|> visitWithListOfVisitors expressionRelatedVisitors.expressionVisitorsOnExit node
|
||||
|
||||
|
||||
@ -5582,12 +5572,7 @@ visitOnlyExpressions expressionVisitorsOnEnter expressionVisitorsOnExit node err
|
||||
-- IGNORE TCO
|
||||
errorsAndContext
|
||||
|> visitWithListOfVisitors expressionVisitorsOnEnter node
|
||||
|> (\errorsAndContext_ ->
|
||||
List.foldl
|
||||
(visitOnlyExpressions expressionVisitorsOnEnter expressionVisitorsOnExit)
|
||||
errorsAndContext_
|
||||
(expressionChildren node)
|
||||
)
|
||||
|> ListExtra.foldlSwitched (visitOnlyExpressions expressionVisitorsOnEnter expressionVisitorsOnExit) (expressionChildren node)
|
||||
|> visitWithListOfVisitors expressionVisitorsOnExit node
|
||||
|
||||
|
||||
|
13
src/Vendor/ListExtra.elm
vendored
13
src/Vendor/ListExtra.elm
vendored
@ -2,6 +2,7 @@ module Vendor.ListExtra exposing
|
||||
( find, last
|
||||
, orderIndependentMapAppend, orderIndependentConcatMapAppend
|
||||
, anyCombination
|
||||
, foldlSwitched
|
||||
)
|
||||
|
||||
{-| Functions taken from elm-community/list-extra.
|
||||
@ -54,6 +55,18 @@ last items =
|
||||
last rest
|
||||
|
||||
|
||||
{-| Same as List.foldl but the position of the list and initial value arguments are switched.
|
||||
-}
|
||||
foldlSwitched : (a -> b -> b) -> List a -> b -> b
|
||||
foldlSwitched func list acc =
|
||||
case list of
|
||||
[] ->
|
||||
acc
|
||||
|
||||
x :: xs ->
|
||||
foldlSwitched func xs (func x acc)
|
||||
|
||||
|
||||
|
||||
-- Not originally from elm-community/list-extra
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user