An infix call places a one-parameter function between its receiver and argument, removing parentheses and other separators. The syntax makes operator-like calls concise while remaining an ordinary function invocation. section 3.4.3 section 3.7
1.to("one") #1
1 to "one" #2
These two calls are equivalent; the second uses infix notation. section 3.4.3
Use infix notation only when the function satisfies these requirements:
- Mark the function with the infix modifier. section 3.4.3
- Give it exactly one required parameter. section 3.4.3
- Use either a regular member function or an extension function. section 3.4.3
Building pairs and maps
The standard-library extension function to creates a Pair, so `1 to "one"` reads more naturally than `1.to("one")`. Pair values can feed mapOf and can later be unpacked with a destructuring declaration. section 3.4.3
Readable test DSLs
In Kotest, `s should startWith("K")` chains an infix should function with a matcher, producing assertion code that reads almost like English while remaining statically typed. section 13.4.1
