diff --git a/core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt b/core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt index 7af2fc1cad..22617a4ee6 100644 --- a/core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt +++ b/core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt @@ -11,4 +11,19 @@ operator fun Point.times(other: Point): Point = Point(x * other.x, y * other.y) operator fun Point.div(other: Point): Point = Point(x / other.x, y / other.y) operator fun Point.rem(other: Point): Point = Point(x % other.x, y % other.y) operator fun Point.times(factor: Int): Point = Point(x * factor, y * factor) -operator fun Int.times(point: Point): Point = Point(point.x * this, point.y * this) \ No newline at end of file +operator fun Int.times(point: Point): Point = Point(point.x * this, point.y * this) + +class Shape { + private val points = mutableListOf() + + operator fun Point.unaryPlus() { + points.add(this) + } +} + +fun shape(init: Shape.() -> Unit): Shape { + val shape = Shape() + shape.init() + + return shape +} \ No newline at end of file diff --git a/core-kotlin/src/main/kotlin/com/baeldung/operators/UI.kt b/core-kotlin/src/main/kotlin/com/baeldung/operators/UI.kt deleted file mode 100644 index abb4a4a00c..0000000000 --- a/core-kotlin/src/main/kotlin/com/baeldung/operators/UI.kt +++ /dev/null @@ -1,30 +0,0 @@ -interface View -class TextView(val value: String) : View -class ImageView(val url: String) : View - -class UI { - private val views = mutableListOf() - - operator fun String.unaryPlus() { - views.add(TextView(this)) - } - - operator fun View.unaryPlus() { - views.add(this) - } -} - -fun ui(init: UI.() -> Unit): UI { - val ui = UI() - ui.init() - - return ui -} - -fun main(args: Array) { - val header = ui { - +ImageView("http://logo.com") - +"Brand name" - +"Brand description" - } -} \ No newline at end of file