Nested lambda calls in Kotlin

前端 未结 1 1043
栀梦
栀梦 2020-12-17 09:52

When nesting lambda calls in Kotlin, how can I unambiguously refer to child\'s and parent\'s it element? For instance:

data class Course(var wee         


        
相关标签:
1条回答
  • 2020-12-17 10:31

    it always refers to the innermost lambda's parameter, to access outer ones, you have to name them. For example:

    list1.filter { a -> list2.none { b -> a.weekday == b.weekday && a.time == b.time} }
    

    (You could leave the inner one as it, but it's a bit nicer if you name that too, in my opinion.)

    Edit: @mfulton26 linked the relevant documentation below, see that for more details.

    0 讨论(0)
提交回复
热议问题