I'm trying to get index route of a value from a nested data structure.

I've written some code but it does not work properly

(defn helper [val form c index] (loop [f form i index l 0] (if (seq f) (if (or (list? (first f)) (vector? (first f))) (helper val (first f) (conj c l) (inc i)) (if (= val (first f)) (conj c l) (recur (rest f) (inc i) (inc l)))) nil))) (defn find-indexes [val form c index] (when (seq form) (if-let [result (helper val form c index)] result (find-indexes val (rest form) c (inc index))))) (defn find-index-route [val form] (find-indexes val form [] 0))

Current behaviour:

(find-index-route :my-key '(1 2 ("a" :my-key))) ;=> [2 1] "Works" (find-index-route :my-key '(1 2 ("a" ["b" 3 :my-key]))) ;=> [2 1 2] "Works" (find-index-route :my-key '(1 2 ("a" ["b" 3 () :my-key]))) ;=> nil "Does NOT Work" (find-index-route :my-key '(1 2 ("a" [] ["b" 3 :my-key]))) ;=> nil "Does NOT Work" (find-index-route :my-key '(1 2 [] ("a" ["b" 3 :my-key]))) ;=> [0 1 2] "It has to be [3 1 2]"

The thing is if the function hits empty list or vector before finding the value it returns nil or 0(just for first the level)

The behaviour I need: