Vitali Plagov
01/02/2020, 1:38 PM"one ".trim()
"two ".trim()
"three ".trim()
I would like to improve it with use of scope functions like run
, with
, etc. Can I do with them something like this:
<scope_function> {
"one ",
"two ",
"three ".
}.trim()
?LeoColman
01/02/2020, 1:39 PMLeoColman
01/02/2020, 1:40 PMtrim
, but they're being used on different objectsSiebelsTim
01/02/2020, 1:40 PMLeoColman
01/02/2020, 1:40 PMLeoColman
01/02/2020, 1:41 PMlistOf("one ", "two ", "three ").map { it.trim() }
LeoColman
01/02/2020, 1:41 PMVitali Plagov
01/02/2020, 1:42 PMSiebelsTim
01/02/2020, 1:43 PMVitali Plagov
01/02/2020, 1:43 PMLeoColman
01/02/2020, 1:44 PMlistOf(...).map { try {it.trim()} catch(e: Exception) { .. }}
Vitali Plagov
01/02/2020, 1:44 PMLeoColman
01/02/2020, 1:47 PMVitali Plagov
01/02/2020, 1:50 PMVitali Plagov
01/02/2020, 1:51 PMwbertan
01/02/2020, 2:26 PMprivate fun Collection<String>.trim(): Collection<String> = map(String::trim)
@Test
fun asas1() {
val result = listOf(
"one ",
"two ",
"three "
).trim()
val expectedResult = listOf(
"one",
"two",
"three"
)
assertEquals(expectedResult, result)
}
@Test
fun asas2() {
val result = setOf(
"one ",
"two ",
"three "
).trim()
val expectedResult = listOf(
"one",
"two",
"three"
)
assertEquals(expectedResult, result)
}
LeoColman
01/02/2020, 2:27 PMfun Collection<String>.trim() = this.map { it.trim() }
Vitali Plagov
01/02/2020, 2:27 PMDico
01/02/2020, 9:37 PM