// Created on savesnippets.com ยท https://savesnippets.com/UqZHjaEi7YCRDl // Stdlib examples: `to`, `until`, `step`, `downTo`, `xor`, `or`, `and` fun main() { val pair = "name" to "Alice" // infix `to` for (i in 1 until 5) print(i) // 1234 (infix `until`) for (i in 1..10 step 2) print(i) // 13579 (infix `step`) println() // Custom infix infix fun Int.shouldBe(expected: Int) { require(this == expected) { "expected $expected but got $this" } } (2 + 2) shouldBe 4 // reads naturally // Custom infix on classes (must be a member function or extension) infix fun String.containing(other: String): Boolean = contains(other) println("hello world" containing "world") // true }