Skip to content

Instantly share code, notes, and snippets.

@abdurahmanadilovic
Created January 28, 2018 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdurahmanadilovic/4c0a2fea3ed076a522f7cf8ae67dbfde to your computer and use it in GitHub Desktop.
Save abdurahmanadilovic/4c0a2fea3ed076a522f7cf8ae67dbfde to your computer and use it in GitHub Desktop.
Kotlin map forEach example
@Test
fun kotlinMap() {
val testContext = InstrumentationRegistry.getTargetContext()
val rootView = LinearLayout(testContext)
listOf(
"www.codingstoic.com",
"www.codingblast.com",
"www.kotlinlang.org",
"www.android.com"
).map {
val tmpTextView = TextView(testContext)
tmpTextView.text = it
tmpTextView
}.forEach {
rootView.addView(it)
}
assertEquals("www.codingstoic.com", (rootView.getChildAt(0) as TextView).text.toString())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment