What is the “best” way to format chained infix fun...
# codingconventions
d
What is the “best” way to format chained infix functions? For example, there is an infix
or
function and I want to write something like this:
Copy code
val json =
    obj or
    array or
    string or
    number
However, IDE formats it as:
Copy code
val json =
    obj or
        array or
        string or
        number
And one line can be hard to read for a long list of chained functions:
Copy code
val json = obj or array or string or number
e
personally I'd choose
Copy code
val json = obj or
    array or
    string or
    number
unless the first part doesn't fit on one line, in which case I'd follow your second example
d
This makes sense. Although the first object can be “lost” when the first line is too long, e.g.:
Copy code
private val json: Parser<JsonObject> = obj or
    array or
    string or
    number
e
Copy code
val json = listOf(obj, array, string, number).reduce { a, b -> a or b }
🙃
😂 2
😱 1