-
Notifications
You must be signed in to change notification settings - Fork 9
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
Feature request: inline functions with if
statements
#76
Comments
it is related to how we format code blocks. currently code blocks are always take at least 3 lines. i think we can make a special case for this. |
Fair point; perhaps only when an "else" clause is also specified? |
I propose a way to determine whether to inline
|
That makes sense to me!
Are there additional |
I mean we may only inline {
// DO NOT
if ... {
...
} else {
..
}
let a = if ... { } else { } // DO
let a = f(if ... { } else { }, ...) // DO
let a = (1, 2, if ... { } else { }) // DO
} |
I just realize that the body of if can be content blocks as well, like #if 1 > 2 [ 111 ] else [ 222 ] So maybe we should have a special code path for "simple if"s. If we have a if,
We try to inline it. |
Content blocks should be acceptable too, right? IMO As long as they are short enough, the cognitive complexity is still lower when inlined. All the other conditions make sense to me. |
From my point of view, the first point is good but the second point is not quite good. I don't think it good and robust to check so many conditions:
#table( // named item can be as a function argument
fill: (x, y) => if y == 0 { white.darken(15%) } else { none },
)
#let paint = ( // named item can be as an item of some dictionary literal
stroke: if y == 0 { white.darken(15%) } else { none },
)
I think it is a generally great enough rule to make beautiful named items, and we can find other good rules when someone make another issue. |
I think the reduced complexity makes sense, but I would advocate for #let x = if cond {
5
} else {
6
} However, |
Consider this case:
The function definition is short (< line length) and clearly indicates parameter usage.
typstyle
reformats to:which is arguably less readable.
My request is for inline ternary functions shorter than the user-specified line length to remain one-line.
The text was updated successfully, but these errors were encountered: