I’m trying to write a function to strip all ASCII vowels in Clojure. I am new to Clojure, and I’m having a little trouble with strings. For example the string "hello world" would return "hll wrld". I appreciate the help!
I’m trying to write a function to strip all ASCII vowels in Clojure. I
Share
You can take advantage of the underlying functions on the string class for that.
If that feels like cheating, you could turn the string into a seq, and then filter it with the complement of a set, and then turn that back into a string.
Sets in clojure are also functions.
complementtakes a function and returns a function that returns the logical not of the original function. It’s equivalent to this.applytakes a function and a bunch of arguments and calls that function with those arguments (roughly speaking).edit
One more…
#"[^aeiou]"is a regex, and re-seq turns the matches into a seq. It’s clojure-like and seems to perform well. I might try this one before dropping down to Java. The ones that seq strings are quite a bit slower.Important Edit
There’s one more way, and that is to use
clojure.string/replace. This may be the best way given that it should work in either Clojure or Clojurescript.e.g.