Skip to content

Instantly share code, notes, and snippets.

@AndyObtiva
Created June 20, 2017 11:58
Show Gist options
  • Save AndyObtiva/06ae34d241339f30056b069831973f4c to your computer and use it in GitHub Desktop.
Save AndyObtiva/06ae34d241339f30056b069831973f4c to your computer and use it in GitHub Desktop.
Checks if a particular collection is a prefix of another collection (contained in it at the beginning). e.g. (prefix-of? [1 2] [1 2 3]) returns true whereas (prefix-of? [2 3] [1 2 3]) returns false.
(def prefix-of?
(fn [chunk full]
(or
(empty? chunk)
(and
(=
(take 1 chunk)
(take 1 full)
)
(prefix-of?
(drop 1 chunk)
(drop 1 full)
)
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment