Slide 50
Slide 50 text
@skentphd
Swift
class User {
// ...
var reversedName: String {
return fullName()
.split(separator: " ")
.map { String($0) }
.reversed()
.joined(separator: ", ")
}
}
stuart.reversedName // "Kent, Stuart"
eminem.reversedName // "Eminem"
class User {
// ...
val reversedName: String
get() = fullName()
.split(Regex(" "))
// No explicit cast needed.
.asReversed()
.joinToString(", ")
}
stuart.reversedName // "Kent, Stuart"
eminem.reversedName // "Eminem"
Kotlin