kotlin-style-guide icon indicating copy to clipboard operation
kotlin-style-guide copied to clipboard

About infix function convention

Open doljae opened this issue 2 years ago • 1 comments
trafficstars

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) }

doljae avatar Dec 31 '22 11:12 doljae

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).

JakeWharton avatar Dec 31 '22 17:12 JakeWharton