Created
December 7, 2020 05:35
-
-
Save le0nidas/d1e0da44e06876ba6abc3ed6f2009126 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Person.kt | |
class Person( | |
val name: String, | |
val surname: String | |
) | |
// PeopleScreen.kt | |
class PeopleScreen( | |
private val people: List<Person> | |
) { | |
constructor(people: Map<String,String>) : this( | |
people.map { entry -> Person(entry.key, entry.value) } | |
) | |
fun render() { | |
people.forEachIndexed { index, person -> | |
println("${index + 1}. ${person.name}, ${person.surname}") | |
} | |
} | |
} | |
// Usage: | |
fun main() { | |
val people = mapOf( | |
"Joe" to "Dow", | |
"Jill" to "Doe", | |
"Jack" to "Black" | |
) | |
val screen = PeopleScreen(people) | |
screen.render() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment