diff --git a/MVMCoreUI/Atomic/Protocols/ModelProtocols/MoleculeModelProtocol.swift b/MVMCoreUI/Atomic/Protocols/ModelProtocols/MoleculeModelProtocol.swift index 0fcab2d0..e56840e8 100644 --- a/MVMCoreUI/Atomic/Protocols/ModelProtocols/MoleculeModelProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/ModelProtocols/MoleculeModelProtocol.swift @@ -69,11 +69,12 @@ public extension Array where Element == MoleculeModelProtocol { func depthFirstTraverse(options: TreeTraversalOptions, depth: Int, onVisit: (Int, MoleculeModelProtocol, inout Bool) -> Void) { var shouldStop = false + let stopIntercept = { depth, molecule, stop in + onVisit(depth, molecule, &shouldStop) + stop = shouldStop + } for molecule in self { - molecule.depthFirstTraverse(options: options, depth: depth) { depth, molecule, stop in - onVisit(depth, molecule, &shouldStop) - stop = shouldStop - } + molecule.depthFirstTraverse(options: options, depth: depth, onVisit: stopIntercept) if shouldStop { break } } }