[Date Index] [Thread Index] [Author Index]
Early out with Map?
Hi, Is it possible to interrupt Map before it reaches then end of the list? For example, how would I convert the following from procedural to functional? (* This is the procedural version *) foundSolution = False; For[i =1, i <= numChildren && ! foundSolution, i++, If[testChild[children[[i]]], foundSolution = True; ]; ]; foundSolution (* * This keeps going until it reaches the end of the list. * I would prefer to return as soon as testChild returns True *) Or @@ Map[testChild, children] (* * This does not actually return *) Map[If[testChild[#], Return[True], False]&, children]