Shehab Ellithy
10/04/2023, 1:23 AMbuildList
and family. To me it's semantics instead of (the written-on-phone hence untested block)
mutableListOf<Int>().run {
add(1)
this as List<Int>
}
Here're the advantages I see:
1. `buildList`'s usage, semantically, is clearer
2. No need to cast (but can just specify the type somewhere)
3. buildList
(after the work on the Builder annotation) can infer types so no need to specify any types explicitly
Am I missing something else?
Pure judgment call here, but isn't the work on ListBuilder
and builder annotation too much just for this?
Only point 3 to me seems that worth it to include directly in the languageephemient
10/04/2023, 1:28 AMbuildList
behaves more like
mutableListOf<Int>().run {
add(1)
}.toList()
because the resulting list is actually immutable, not just by the List
type, but also by overriding the mutation methods (since the underlying java.util.List
interface methods may be accessed despite the kotlin.collections.List
interface not containing them)flow
builder which really doesn't have a good alternativeShehab Ellithy
10/04/2023, 1:39 AMflow
builder is (and Google not helping)ephemient
10/04/2023, 1:41 AMShehab Ellithy
10/04/2023, 1:43 AMflow
buildersephemient
10/04/2023, 1:44 AMflow
one is a flow builder, the others are just builders in the same styleShehab Ellithy
10/04/2023, 1:44 AMephemient
10/04/2023, 1:50 AMShehab Ellithy
10/04/2023, 1:54 AM