Scala Graph Cycle Detection Algo 'return' needed?
I have implemented a small cycle detection algorithm for a DAG in Scala. The 'return' bothers me - I'd like to have a version without the return...possible? def isCyclic() : Boolean = { lock.readLock().lock() try { nodes.foreach(node => node.marker = 1) nodes.foreach(node => {if (1 == node.marker && visit(node)) return true}) } finally { lock.readLock().unlock() } false } private def visit(node: MyNode): Boolean = { node.marker = 3 val nodeId = node.id val children = vertexMap.getChildren(nodeId).toList.map(nodeId => id2nodeMap(nodeId)) children.foreach(child => { if (3 == child.marker || (1 =