https://kotlinlang.org logo
#announcements
Title
# announcements
r

radityagumay

11/09/2017, 2:13 AM
Hi, is anyone facing this problem.
Copy code
break or continue jump across class boundary kotlin
this problem appears when i am going to use break or continue. inside lamda with receiver i create ‘letIn’
Copy code
lamda with receiver code
fun letIn(componentName: String?, values: List<LifeService.Value?>?,
          body: (String, List<LifeService.Value?>) -> Unit) {
    if (!TextUtils.isEmpty(componentName) && (values != null && values.isNotEmpty())) {
        body(componentName!!, values)
    }
}
this sample code for it.
Copy code
for (option in 0 until optionsSize) {
val component = optionsGroup?.options?.get(option)
        component?.let {
            with(component) {
                letIn(presentation, values, { componentName, values ->
                    if (componentName == LifeComponentViewType.CHECKBOX) {
                        letIn(transformCheckBoxValues(optionsGroup), { data ->
                            dataSource?.push(componentName, ComponentDataCheckBoxCollection(name, data))
                            view.buildComponent(componentName)
                            // break or return doesnt work
                        })
                    } else {
                        dataSource?.push(componentName, ComponentDataCollection(name, values))
                        view.buildComponent(componentName)
                    }
                })
            }
        }
}
because above code didnt work so i use imperative way.
Copy code
for (option in 0 until optionsSize) {
            val component = optionsGroup?.options?.get(option)
            if (component != null) {
                val presentation: String? = component.presentation
                val values = component.values
                if (!TextUtils.isEmpty(presentation)) {
                    if (presentation == LifeComponentViewType.CHECKBOX) {
                        val data = transformCheckBoxValues(optionsGroup)
                        if (data.isNotEmpty()) {
                            dataSource?.push(presentation, ComponentDataCheckBoxCollection(optionsGroup.name, data))
                            view.buildComponent(presentation)
                            return
                        }
                    } else {
                        dataSource?.push(presentation!!, ComponentDataCollection(component.name, values))
                        view.buildComponent(presentation!!)
                    }
                } else {
                    return
                }
            }
        }
does anyone have suggestions?
b

bdawg.io

11/09/2017, 6:47 PM
You can’t perform
return@let
?
By default, “The return-expression returns from the nearest enclosing function” (which means it would skip right past the
let
) http://kotlinlang.org/docs/reference/returns.html#return-at-labels
There’s docs available for
break
and
continue
just above the linked section too
r

radityagumay

11/10/2017, 1:23 PM
Hi, I will deep dive into this problem.
2 Views