Created
October 13, 2010 00:43
-
-
Save devn/623200 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; "Clojure transactions should be easy to understand if you've ever used database | |
| ;; transactions - they ensure that all actions on Refs are atomic, consistent, and | |
| ;; isolated." (http://clojure.org/refs) | |
| (def large-future-data-structure (ref {})) | |
| (def big-text (read-lines (File. "/path/to/my/file"))) | |
| ;; #"" is how you define a regex | |
| ;; dosync is required for transactions with a ref | |
| (defn add-to-structure [line] | |
| (let [match (re-match #"foo" line)] | |
| (dosync | |
| (if match (conj match large-future-data-structure))))) | |
| ;; (fn [x]) can be replaced with the syntactic sugar: #(%) | |
| ;; as in: (map #(inc %) [1 2 3 4]) => [2 3 4 5] | |
| ;; or: (map #(+ % %) [1 2 3 4]) => [2 4 6 8] | |
| (.start (Thread. (fn [] (map add-to-structure big-text)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment