Kotlin Sequence Initialization (KSI)


KSI:   SOLD       




Hi guys, I'd like to share a little experience while working with ChipGroup components.

sheetProduct.chipGroup.setOnCheckedChangeListener { group, checkedId ->
            child = group.children
                .filter { (it as Chip).isChecked }
                .map { (it as Chip).text.toString() }

            Log.i("WTFCHIP", "chip $checkedId GROUP ${child.joinToString(", ")}")
            ids.add(ProductModel(id = checkedId))
            if (ids.isNotEmpty()) sheetProduct.submit.visibility = View.VISIBLE else sheetProduct.submit.visibility =
                View.GONE
        }

When I have to expand the scope of a variable from a child of type  Sequence<String>(), then I have to initialize it first.. this is how it works.

var child = sequenceOf("")

Along with collections, the Kotlin standard library contains another container type – sequences ( Sequence<T>). Sequences offer the same functionality as Iterable but implement a different approach to multi-step collection processing.

The order of execution of operations is also different: Sequence performs all processing steps one by one for each element. In turn, Iterable completes each step for the entire collection and then proceeds to the next step.


Post a Comment

Previous Next

نموذج الاتصال