The point of using closure expressions is to clearly express a succinct bit of logic. Start nesting closure expressions too deeply and you create a logic snarl that will likely snare both you and future maintainers.


== Noncompliant Code Example

With the maximum depth of 2:

----
foo(42) { (x: Int) in
    bar(x) { (x: Int) in
      foobar(x) { // Noncompliant
        print(x * 42)  
      }
      print(x + 42)
    }
    print(x - 42)
}
----


== Compliant Solution

----
func multPlus(x:Int) {
  foobar(x) {
    print(x * 42)  
  }
  print(x + 42)
}

foo(42) { (x: Int) in
    bar(x, multPlus) 
    print(x - 42)
}
----

