``` fun searchParent(id: String): Module? { mod...
# android
s
Copy code
fun searchParent(id: String): Module?
	{
		modules.forEach { module ->
			val ret = searchParent(module, id)

			if (ret != null)
			{
				return@searchParent ret
			}
		}

		return null
	}
k
return@searchParent
does a local return (within the lambda) rather than a function return. You need to
return ret
instead
s
i had that originally which was the problem
k
Oh. Looking at your code.
return@searchParent
isn’t even valid code
s
lol it compiles 😛
😱 1
k
What problem did you have with simple
return xyz
s
it continues the loop after i've returned
i have a recursive datastructure and this basically loops through each one until it finds the matching ID then returns the parent object
the recursive method:
Copy code
fun searchParent(root: Module, id: String): Module?
	{
		root.steps?.forEach { step ->
			val ret = searchParent(step, id)

			if (ret == null)
			{
				if (step.id == id)
				{
					return root
				}
			}
		}

		return null
	}
m
return@searchParent should be correct (non-local return), but just use a for loop, it's shorter too
s
yeah i think that'll probably be the best, just trying to use lambdas as much as possible to get used to them
ok I fixed it! after writing it in plain java then refactoring it to kotlin worked cheers 👍