!
연산자를 오버로딩하면 안된다.operator fun Int.not() = factorial()
print(10 * !6) // 7200
// 모든 연산자는 함수로도 호출 가능하다. 6.not()
// not이 팩토리얼 계산 함수라는 것은 혼란스럽다.
operator fun Int.times(operation: () -> Unit): () -> Unit =
{ repeat(this) { operation } }
val tripleHello = 3 * { print("Hello") }
tripleHello() // HelloHelloHello
infix
를 활용한 확장 함수를 사용하면 좋다.repeat
함수는 이미 톱레벨 함수에 stdlib에 구현되어 있다.repeat(3) { print("Hello") }
body {
div {
+"Some text" // String.unaryPlus
}
}