interface Iterator { fun next() : T val hasNext : Boolean fun map(transform: (element: T) -> R) : Iterator = object : Iterator { override fun next() : R = transform(this@map.next()) override val hasNext : Boolean // There's no 'this' associated with the map() function, only this of the Iterator class get() = this@map.hasNext } }