elect
10/27/2022, 9:04 AMcapitalize()
: Gradle is using capitalized()
Joffrey
10/27/2022, 10:02 AMcapitalize
. The point is that it's unclear what this does, and many devs have different expectations depending on their background. Does it capitalize every word? Just the first character? With which locale? Does it lowercase other letters of keep them uppercase if they are uppercase to start with?elect
10/27/2022, 11:33 AMJoffrey
10/27/2022, 2:09 PMcapitalize(d)
. The reason the Kotlin team deprecated this function is that there was no consensus on this, and therefore it was better to keep more specific helper functions, like replaceFirstChar
and see how users combined them. Once this data is clearer, maybe a new helper will be provided in the stdlib, with a name adapted to the most common usages/use cases.ilya.gorbunov
10/28/2022, 3:02 PMreplaceFirstChar { it.uppercase() }
may be sufficient.Joffrey
10/28/2022, 3:03 PMRescribet
03/10/2023, 1:02 PMuppercase()
is unambiguous than so should uppercaseFirstChar()
?
This and pascal/camel/snake case conversions come up quite often.Joffrey
03/10/2023, 1:09 PMreplaceFirstChar { it.uppercase() }
is probably also not what people should be using. Most probably people are looking for replaceFirstChar { it.titlecase() }
instead (see the stackoverflow answer linked above), and thus introducing uppercaseFirstChar
would probably be a bad idea, but I see your point (we could make the same point with titlecaseFirstChar
).
The thing is, replaceFirstChar
is a general function which can be combined in a more flexible way. It makes sense to understand actual needs before releasing functions in the stdlib.Joffrey
03/10/2023, 1:10 PM