Hi!
I think infix operators with lower precedence than |>
and <|
could be useful:
Case 1:
Operator =>
is pretty useful for creating tuples with two values - some examples:
- Example from rocket-update 1.0.0
button [ style [ "display" => "none" ] ] [ text "invisible!" ]
- Example from rocket-update 1.0.0
SendOtherRequest ->
model
|> doSomethingToModel
|> doSomethingElseToModel
=> [ Http.send someOtherRequest ]
- Example
Json.Encode.object
[ "states" => projectData.states |> statesEncoder
, "something" => ...
Problem:
There is a bug in example 3 - "states" => projectData.states |> statesEncoder
throws
“Conflicting associativity for binary operators (=>, |>). Consider adding parentheses to disambiguate.”
Packages with operator =>
:
- rocket-update 1.0.0
- Basics.Extra - basics-extra 3.0.1
- Tuple2 - elm-tuple-extra 3.0.0
- http://package.elm-lang.org/packages/danielspaniol/elm-tuple-extra/1.0.0/Tuple2-Infix
Case 2:
I often have to rewrite <| something
to ( something )
due to conflicting operators <|
and |>
.
1. Example without pipeline
SetTitle <| toString aNumber
2. Example with pipeline
SetTitle (aNumber |> toString)
Problem:
I thought I can remove extra parentheses - just implement an operator <||
(something like <|
on steroids) and write:
SetTitle <|| aNumber |> toString
But set precedence with infix -1 <||
is not possible. (See Elm (language) FAQ and docs/syntax)
Case 3:
Precedence of the operator !
is a little bit counter-intuitive - I think it should have been processed after pipelines. (Not only mine experience + https://github.com/elm-lang/core/issues/638)
Conclusion
I agree that infix operators shouldn’t be used very often but I think some cases exist where they can make code more readable and simpler for refactoring. But with limited precedence settings some of these cases are not possible.
Thank You for feedback!