groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "mg (JIRA)" <j...@apache.org>
Subject [jira] [Created] (GROOVY-8301) break/return/continue support in "Appended Block Closures"
Date Sun, 27 Aug 2017 14:44:00 GMT
mg created GROOVY-8301:
--------------------------

             Summary: break/return/continue support in "Appended Block Closures"
                 Key: GROOVY-8301
                 URL: https://issues.apache.org/jira/browse/GROOVY-8301
             Project: Groovy
          Issue Type: Proposal
          Components: Compiler
            Reporter: mg


This proposal revisits the idea to change the semantics of the break, return, and continue
keyword for closures that are used in a way that mimics Java block constructs such as if,
for, or while.

Example 1:
{code}
// Iterate over all PERSON rows in the result set
sqe.forEachRow("select * from PERSON") { final row ->
  if(row.TAG == 0) { break } // Leave forEachRow loop
  if(row.TAG == 1) { return } // return from the method enclosing the forEachRow loop
  if(row.TAG == 2) { continue } // Move to next iteration in the forEachRow loop
}
{code}


Example 2:
{code}
// Encapsulate with statically imported helper method that catches exceptions and ignores
them, if the passed parameter is true
execWithOptionalIgnoreErrors(ignoreErrorsQ) {
  final x = dangerousOperation() 
  if(x == 1) { return } // return from the enclosing method
  // Note: break & continue are not allowed here
}
{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message