Skip to content

Commit

Permalink
Expose pipeLeft
Browse files Browse the repository at this point in the history
  • Loading branch information
mdgriffith committed May 27, 2024
1 parent f8c26de commit 0086a90
Showing 1 changed file with 2 additions and 67 deletions.
69 changes: 2 additions & 67 deletions src/Elm/Op.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Elm.Op exposing
, append, cons
, plus, minus, multiply, divide, intDivide, power
, lt, gt, lte, gte
, pipe
, pipe, pipeLeft
, parens
, keep, skip
, slash, query
Expand Down Expand Up @@ -39,7 +39,7 @@ Would generate
@docs lt, gt, lte, gte
@docs pipe
@docs pipe, pipeLeft
@docs parens
Expand Down Expand Up @@ -622,68 +622,3 @@ popLast lst =

last :: initReverse ->
Just ( List.reverse initReverse, last )


{-|
String.append "world2" (String.append "world" "Hello")
Apply [ String.append, "world2", Apply [ String.append, "world", "hello" ] ]
Elm.string "Hello"
|> Elm.Gen.String.append (Elm.string "world")
|> Elm.Gen.String.append (Elm.string "world2")
OpApply "|>"
(OpApply "|>"
()
(Apply [ String.append, "world" ])
)
String.append
-}
autopipe : Bool -> Exp.Expression -> List Exp.Expression -> Exp.Expression
autopipe committed topFn expressions =
if committed then
case popLast expressions of
Nothing ->
topFn

Just ( init, last ) ->
Exp.OperatorApplication "|>"
Infix.Left
(Compiler.nodify last)
(Compiler.nodify
(Exp.Application
(Compiler.nodify topFn :: List.map (Compiler.nodify << Compiler.parens) init)
)
)

else
case popLast expressions of
Nothing ->
topFn

Just ( init, last ) ->
case last of
Exp.Application lastArgs ->
Exp.OperatorApplication "|>"
Infix.Left
(Compiler.nodify
(case lastArgs of
[] ->
Exp.Application []

(Node _ innerFn) :: remain ->
autopipe True innerFn (Compiler.denodeAll remain)
)
)
(Compiler.nodify
(Exp.Application
(Compiler.nodify topFn :: List.map (Compiler.nodify << Compiler.parens) init)
)
)

_ ->
Exp.Application
(List.map (Compiler.nodify << Compiler.parens) (topFn :: expressions))

0 comments on commit 0086a90

Please sign in to comment.