edrd
09/16/2021, 8:34 PMString.prepend(value: String) in the stdlib? I need it quite often and .let { "prefix$it" } doesn't express intent so well.Shawn
09/16/2021, 8:45 PMval myString = "prefix" + getStringToPrependTo()edrd
09/16/2021, 9:18 PMfun String.normalizeHttpsUrl() =
if (string.startsWith("https://")) this
else this.prepend("https://")
is more human-readable than this:
fun String.normalizeHttpsUrl() =
if (string.startsWith("https://")) this
else "https://$this"edrd
09/16/2021, 9:19 PMmbonnin
09/16/2021, 10:35 PM"https://${this.removePrefix("https://")}" for this specific exampleGuilherme Cordeiro
09/17/2021, 2:01 PMfun String.normalizeHttpsUrl() =
if (string.startsWith("https://")) this
else "https://".append(this)
Just an opinion, but this reads nice too, as the parts are in the order they'll appear on the final stringedrd
09/19/2021, 1:18 PMval result: String? = someNullableString
?.doSomeTransformation()
?.prepend("something")
IMO it reads better than
val result: String? = someNullableString
?.doSomeTransformation()
?.let { "something$it" }edrd
09/19/2021, 1:19 PM.let by using .plus