Will "It" variable stay or go?

 

class Tree(val data: String, children: List<Tree>)

tree.forEach {
  if (it.data != “special”) {
  it.children.filter {
  it.data == “special” // it’s NOT the same “it.data” as two lines above, but nothing suggests that in the syntax
  }
  }
}

Worse than that: sometimes it's the same "it.data": when the nested lambda does not have a parameter at all

3 Likes