diff --git a/src/main/kotlin/lesson2/idiom14-15.kt b/src/main/kotlin/lesson2/idiom14-15.kt index 38b1493..c73c8fa 100644 --- a/src/main/kotlin/lesson2/idiom14-15.kt +++ b/src/main/kotlin/lesson2/idiom14-15.kt @@ -1,9 +1,26 @@ package lesson2 +/** + * Extension property on a String. It is not monkey-patching. + */ fun String.countOs(): Int = count { it == 'о' } // implicit this points to String fun Int.printMe() = println(this) // explicit this fun main() { "обороноспособность".countOs().printMe() -} \ No newline at end of file +} + +/** + * Extension property (must be virtual) + */ +val List.odd get() = filter { it % 2 == 1 } + +/** + * Extension variable (also must be virtual) + */ +var Array.second: Int + get() = get(1) + set(value) { + set(1, value) + } \ No newline at end of file