Kotlin / kotlin-style-guide

Work-in-progress notes for the Kotlin style guide
288 stars 14 forks source link

About infix function convention #47

Open doljae opened 1 year ago

doljae commented 1 year ago

Is there a style guide or convention for how to declare an infix function? I wonder what is the officially recommended way, or what is the most used way.

1

infix fun Class.test(something: Something): Class = this.test(something)

2

infix fun Class.test(something: Something): Class = test(something)

3

infix fun Class.test(something: Something): Class { return this.test(something) }

4

infix fun Class.test(something: Something): Class { return test(something) }
JakeWharton commented 1 year ago

None of those options have anything specific to do with the use of infix but are general variations on ways to write the body of an extension function (or a non-extension member function).