Skip to content

Instantly share code, notes, and snippets.

@le0nidas
Created December 7, 2020 05:35
Show Gist options
  • Save le0nidas/d1e0da44e06876ba6abc3ed6f2009126 to your computer and use it in GitHub Desktop.
Save le0nidas/d1e0da44e06876ba6abc3ed6f2009126 to your computer and use it in GitHub Desktop.
// 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