File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1060,12 +1060,18 @@ prettyOperatorApplication aliases indent symbol dir (Node _ exprl) (Node _ exprr
10601060 Right ->
10611061 ( prec + 1 , prec )
10621062
1063+ -- Lambda expressions need explicit parentheses on either side
1064+ -- of operators. On the right: `a |> \x -> b` is ambiguous.
1065+ -- On the left: `\x -> x <| "hello"` absorbs <| into the body.
10631066 ( left, breakLeft ) =
1064- prettyExpressionInner aliases { precedence = lprec } indent exprl
1067+ case exprl of
1068+ LambdaExpression _ ->
1069+ prettyExpressionInner aliases { precedence = lprec } indent exprl
1070+ |> Tuple . mapFirst Pretty . parens
1071+
1072+ _ ->
1073+ prettyExpressionInner aliases { precedence = lprec } indent exprl
10651074
1066- -- Lambda expressions on the right side of operators like |>
1067- -- need explicit parentheses because `a |> \x -> b |> \y -> c`
1068- -- is ambiguous — the second |> could be inside the lambda body.
10691075 ( right, breakRight ) =
10701076 case exprr of
10711077 LambdaExpression _ ->
Original file line number Diff line number Diff line change @@ -133,4 +133,20 @@ pipes =
133133 ( Elm . fn ( Elm . Arg . var " y" ) ( \ y -> y))
134134 |> Elm . Expect . renderedAs
135135 """ "hello" |> (\\ x -> x) |> (\\ y -> y)"""
136+ , test " pipeLeft with lambda is parenthesized" <|
137+ \ _ ->
138+ Elm . Op . pipeLeft
139+ ( Elm . fn ( Elm . Arg . var " x" ) ( \ x -> x))
140+ ( Elm . string " hello" )
141+ |> Elm . Expect . renderedAs
142+ """ (\\ x -> x) <| "hello\""" "
143+ , test " pipeLeft with lambda applied to complex expression" <|
144+ \_ ->
145+ Elm.Op.pipeLeft
146+ (Elm.fn (Elm.Arg.var " x" )
147+ (\x -> Elm.Op.append x (Elm.string " ! " ))
148+ )
149+ (Elm.string " hello" )
150+ |> Elm.Expect.renderedAs
151+ " " " ( \\ x -> x ++ " !" ) <| " hello\" " " "
136152 ]
You can’t perform that action at this time.
0 commit comments