Skip to content

Commit

Permalink
improve performance with refactor of Builder.linesMap
Browse files Browse the repository at this point in the history
  • Loading branch information
decioferreira committed Feb 9, 2025
1 parent 7ee1263 commit 8eb8b31
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/Compiler/Generate/JavaScript/Builder.elm
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,22 @@ merge a b =

linesMap : (a -> Builder -> ( Lines, Builder )) -> List a -> Bool
linesMap func xs =
List.foldl
(\a ( lines, builder ) ->
Tuple.mapFirst (\line -> line :: lines) (func a builder)
)
( [], emptyBuilder 0 )
xs
|> Tuple.first
|> List.member Many
linesMapHelp func xs (emptyBuilder 0)


linesMapHelp : (a -> Builder -> ( Lines, Builder )) -> List a -> Builder -> Bool
linesMapHelp func xs builder =
case xs of
[] ->
False

a :: rest ->
case func a builder of
( Many, _ ) ->
True

( _, newBuilder ) ->
linesMapHelp func rest newBuilder


commaSepExpr : (a -> Builder -> Builder) -> List a -> Builder -> Builder
Expand Down

0 comments on commit 8eb8b31

Please sign in to comment.