BMG
11/20/2018, 12:41 PMval updatedDataElementsOne = removeExtraElements(info)
val updatedDataElementsTwo = updateExistingElements(updatedDataElementsOne)
return populateEmptyElements(updatedDataElementsTwo)
bitkid
11/20/2018, 12:57 PMAndreas Sinz
11/20/2018, 12:58 PMfun List<T>.removeExtraElements(): List<T> {
//Do work
//Return new list
}
fun List<T>.updateExistingElements(): List<T> {
//Do work
//Return new list
}
//usage
list.removeExtraElements().updateExistingElements()
BMG
11/20/2018, 1:05 PMpopulate
operation in that chain where I need to add some elements at the end of the list.
@Andreas Sinz I assumed that extensions were overkill for this. But I really like the chaining ability it gives!Andreas Sinz
11/20/2018, 1:08 PMList<T>
, otherwise you end up with a huge list of entries in code completionAndreas Sinz
11/20/2018, 1:10 PMBMG
11/20/2018, 1:13 PMprivate
extensions. I have mainly three operations with some business logic,
1) update elements
2) remove elements at the end (dropLast
)
3) add some elements at the endAndreas Sinz
11/20/2018, 1:15 PMlist.map { //Update elements }
.dropLast(10)
.run { this + listOf(a, b, c) }
BMG
11/20/2018, 1:17 PMlist
.mapIndexed {
// 10 lines of code which modifies each element
}
.dropLast {
calculatedNumberOfElementsToRemove()
}
.run {
// 10 lines of code to add new elements
}
BMG
11/20/2018, 1:19 PMdave08
11/21/2018, 3:17 AMmapIndexed
say, then you could just call it mapIndexed(businessLogicObjInstance::myFunction)
. You then avoid the extra lambda.