Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

statefule take-while solution a little shorter then loop solution

  • Loading branch information...
commit 8990b3462b2df28d9cff8b0a22987e68d94f0a02 1 parent b427234
Alex Baranosky authored
Showing with 9 additions and 12 deletions.
  1. +9 −12 src/slam/hound.clj
View
21 src/slam/hound.clj
@@ -3,7 +3,8 @@
[slam.hound.asplode :refer [asplode]]
[slam.hound.regrow :refer [regrow]]
[slam.hound.stitch :refer [stitch-up]])
- (:import (java.io File FileReader PushbackReader)))
+ (:import (java.io File FileReader PushbackReader))))
+
(defn reconstruct [filename]
;; Reconstructing consists of three distinct phases:
@@ -22,17 +23,13 @@
(defn- body-from-file [file-name old-ns-form]
(let [file-contents (slurp file-name)
- num-non-white-chars-in-old-ns-form (count (filter non-whitespace-char? (str old-ns-form)))]
- (apply str (loop [non-white-so-far 0
- file-contents-remaining file-contents]
- (cond (>= non-white-so-far num-non-white-chars-in-old-ns-form)
- file-contents-remaining
-
- (non-whitespace-char? (first file-contents-remaining))
- (recur (inc non-white-so-far) (rest file-contents-remaining))
-
- :else
- (recur non-white-so-far (rest file-contents-remaining)))))))
+ num-non-white-chars-in-old-ns-form (count (filter non-whitespace-char? (str old-ns-form)))
+ non-white-so-far (atom 0)]
+ (apply str (drop-while (fn [ch]
+ (when (non-whitespace-char? ch)
+ (swap! non-white-so-far inc))
+ (< @non-white-so-far num-non-white-chars-in-old-ns-form))
+ file-contents))))
(defn- swap-in-reconstructed-ns-form [file]
(let [new-ns (.trim (reconstruct file))
Please sign in to comment.
Something went wrong with that request. Please try again.