Skip to content

Instantly share code, notes, and snippets.

@borkdude
Last active December 2, 2020 06:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borkdude/533beb1b833828092c35 to your computer and use it in GitHub Desktop.
Save borkdude/533beb1b833828092c35 to your computer and use it in GitHub Desktop.
Clojure vs. Java
Java pre version 8:
public class StringUtils {
public static boolean isBlank(String str) {
int strLen;
if (str == null || (strLen = str.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if ((Character.isWhitespace(str.charAt(i)) == false)) {
return false;
}
}
return true;
}
}
Java 8:
boolean allBlank(String str) {
return str.chars().allMatch( c -> Character.isWhitespace(c));
}
Clojure:
(defn blank? [s] (every? (fn [c] (Character/isWhitespace c)) s))
@ku1ik
Copy link

ku1ik commented Dec 12, 2015

Re Clojure version, I think this could be simpler, like this:

(defn blank? [s] (every? Character/isWhitespace s))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment