Advertisement
mark-naylor-1701

Clojure index-of

Jan 1st, 2025 (edited)
3,060
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. (defn- seq-index-of
  3.   "If ys is a subsquence of xs, return the index of where it occurs, nil
  4.  otherwise."
  5.   [xs ys]
  6.   (let [slv? (some-fn seq? list? vector?)]
  7.    (when (and (slv? xs) (slv? ys))
  8.      (let [idx (.indexOf xs (first ys))]
  9.        (when (and ((complement neg?) idx)
  10.                   (= ys (take (count ys) (drop idx xs))))
  11.          idx)))))
  12.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement