From a8fe71e26f8354209006bc1b6cd4e0394a639a33 Mon Sep 17 00:00:00 2001 From: Damian Niemczyk Date: Mon, 25 Jan 2016 21:30:57 +0100 Subject: [PATCH] Update java string methods to clojure functions With Clojure 1.8.0 finally those string methods now have corresponding Clojure functions. Of note here is that the clojure.string/index-of function responds with nil if nothing is found and not -1 as .IndexOf previously did. --- resources/koans.clj | 2 +- src/koans/02_strings.clj | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/resources/koans.clj b/resources/koans.clj index b73f9fc..1ae5b97 100644 --- a/resources/koans.clj +++ b/resources/koans.clj @@ -24,7 +24,7 @@ "olleh" "hello" 13 - -1 + nil "hello world" true false diff --git a/src/koans/02_strings.clj b/src/koans/02_strings.clj index 92f4817..af4e555 100644 --- a/src/koans/02_strings.clj +++ b/src/koans/02_strings.clj @@ -37,13 +37,13 @@ (= __ (string/reverse "hello")) "Maybe you want to find the index of the first occurence of a substring" - (= 0 (.indexOf "hello world" __)) + (= 0 (string/index-of "hello world" __)) "Or maybe the last index of the same" - (= __ (.lastIndexOf "hello world, hello" "hello")) + (= __ (string/last-index-of "hello world, hello" "hello")) - "But when something doesn't exist, it turns up negative" - (= __ (.indexOf "hello world" "bob")) + "But when something doesn't exist, nothing is found" + (= __ (string/index-of "hello world" "bob")) "Sometimes you don't want whitespace cluttering the front and back" (= __ (string/trim " \nhello world \t \n"))