Since I keep waisting time in recursive functions (and forget what I developped a few months back), here is a piece of code for a recursive function in Groovy.

def getAllChildren(entityId) {
                //Container for the results
		def results = []
		//Retrieve your first element from somewhere
		def entity = entityService.getEntity(entityId)
		if (entity) {
			results.add([entity.id,entity.label])
			entity.children?.each { child ->
				results.addAll(getAllChildren(child))
			}
		}
		return results
	}

 

Posted by xpo6

Software developer in the realm of AI, NLP and black magic.