Which one is more kotliner: A “Builder” object fun...
# compose
s
Which one is more kotliner: A “Builder” object functions should (1️⃣return this ) or (2️⃣let me use with/apply etc and don’t return this)
2️⃣ 16
1️⃣ 2
e
Correct me if i’m wrong but you mean: 1️⃣
Copy code
Builder()
  .function()
  .anotherFunction()
  .build()
2️⃣
Copy code
Builder().apply {
  function()
  anotherFunction()
}
right?
l
No builder and default argument values is more Kotliny
7
👆 1
👍 1
☝️ 4
m
Even if you return this, you can stull use with/apply etc., so I do not see why you would not return this if you are using builder. There is no downside. But otherwise I agree with @louiscad
1
s
Thanks. Efeturi that's correct.
Louis, Regarding the default argument, this is more like StringBuilder, it actually is AnnotatedStringBuilder in order to assist construction of a styled string
StringBuilder seems to be an alias to java one, so I wasn't sure what it would look like if was implemented in kotlin
Thank you all for the responses.
l
Don't you already have
buildSpannedString { … }
+ extensions for
SpannedStringBuilder
in AndroidX Core KTX? You would just add another one for annotations, right?
s
AnnotatedString.Builder will be a Compose component and will be the equivalent of/similar SpannableStringBuilder. Planning to add buildAnnotatedString {...}.
l
Oh yeah, that's why this thread is in the #compose channel. Will it be Android only, or multiplatform ready?
s
AnnotatedString is a regular data class
l
How would that work with localization? A big when expression? Retrieve from resources on Android? Something else?
Also, is there a reason this doesn't implement
Appendable
?
s
Regarding i18n, that is a wider concept and not defined yet.
Regarding appendable, no charsequence support for now. Charsequence bites us on android.
Wait :) I understand that you think AnnotatedString is directly related to annotation class and tag on Android?
If so, that is not something we intended to :/
l
I though it was related to the annotation spans you can put in string resources or
SpannedString
, but it seems it's not after all.
Charsequence bites us on android
How?