Skip to content

Instantly share code, notes, and snippets.

@raspasov
Created December 5, 2014 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raspasov/f04635aaa7a6f2220108 to your computer and use it in GitHub Desktop.
Save raspasov/f04635aaa7a6f2220108 to your computer and use it in GitHub Desktop.
Clojure substring search
(defn string-contains?
"Searches a string s for any number of sub-strings, returns true on the first found, false otherwise"
[s sub & subs]
(if subs
(loop [subs (cons sub subs)]
(if-not (empty? subs)
(if-let [has-sub? (.contains s (first subs))]
has-sub?
(recur (rest subs)))
false))
(.contains s sub)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment