-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is handling of function application followed by infix operators okay? #33
Comments
I prefer the infix operator to not be indented: f1
arg11
arg12
arg13
|> f2 arg21
alpha
+ beta
* gamma |
This is pretty interesting. @Apanatshka's version implies not indenting for infix operators in general. Here's something we have in our code base: model.topicsById
|> Dict.get topicId
|> Maybe.map (not << .premium)
|> Maybe.withDefault False With your suggestion, it would be: model.topicsById
|> Dict.get topicId
|> Maybe.map (not << .premium)
|> Maybe.withDefault False Those both look very readable to me, although the latter saves space and arguably has some consistency benefits. |
On second thought, that looks weird with non-pipes... someNumber
+ anotherNumber
+ aThirdNumber I vote leaving it the way it currently works, including the OP question about indentation levels - it's not my favorite thing, but seems better than the alternatives. |
It looks a little odd, but I still like my way better because it solves the problem in this issue and it's how I style my pipeline code. |
F# people often do their pipes that way. I never do that though. I don't have a strong opinion here though. |
Do we want to style pipelines different from other infix operators? What would be the criteria for that - special case Seems like high potential for added complexity... |
edit: Comments relate to #187Not sure if this belongs here, but I had a block of code like this:person : Random.Generator Person
person =
sex `andThen` \s ->
weight `andThen` \w ->
height `andThen` \h ->
Random.Extra.constant (Person s w h) and elm-format turned it into this: person : Random.Generator Person
person =
sex
`andThen` \s ->
weight
`andThen` \w ->
height
`andThen` \h ->
Random.Extra.constant (Person s w h) Except it was even longer. I don't feel like this is a good formatting style for the |
edit: Comments relate to #187I have a similar gripe with how `andThen` is handled. Maybe the code i'm reading in elm-oracle isn't idiomatic?
turns into
|
edit: Comments relate to #187I recommend using `andThen` with `|>` instead of backticks, like so: andThen = flip Task.andThen
Search sourceFile query ->
tryCatch emitError
<| loadSource sourceFile -- I'd refactor this out; 99% of the time, when I use <| there's a better way
|> andThen (\source -> loadDeps)
|> andThen (\deps -> Task.fromResult (parseDeps deps))
|> andThen (\docPaths -> downloadDocs docPaths)
|> andThen (\_ -> loadDocs docPaths)
|> andThen (\depsDocs -> getProjectDocs)
|> andThen (\projectDocs -> Task.succeed (projectDocs ++ depsDocs))
|> andThen (\docs -> Console.log (Oracle.search query source docs)) |
edit: Comments relate to #187@rtfeldman I don't think that works in this case because some of the lambdas refer to parameters of previous lambdas. Can the pipeline work for cases like that? |
edit: Comments relate to #187@rtfeldman I just tested this and it turned my example intoperson : Random.Generator Person
person =
let
andThen = flip Random.andThen
in
sex
|> andThen (\s -> weight)
|> andThen (\w -> height)
|> andThen (\h -> Random.Extra.constant (Person s w h)) Which doesn't compile, because s w and h are not found in the final function. I can change it to: person : Random.Generator Person
person =
let
andThen = flip Random.andThen
in
sex
|> andThen (\s -> weight
|> andThen (\w -> height
|> andThen (\h -> Random.Extra.constant (Person s w h)))) Which compiles, but elm-format changes it to person : Random.Generator Person
person =
let
andThen = flip Random.andThen
in
sex
|> andThen
(\s ->
weight
|> andThen
(\w ->
height
|> andThen (\h -> Random.Extra.constant (Person s w h))
)
) Which isn't really much better. |
edit: Comments relate to #187Ah, good point - I totally missed that! |
Discussion of the |
the function arguments and the infix operators get indented to the same level, even though they are at different levels in the AST.
The text was updated successfully, but these errors were encountered: