SHARE
TWEET

dropping-transform

a guest May 8th, 2012 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (require '[clojure.java.io :as io])
  2.  
  3. (defn dropping-transform [fn coll]
  4.   (loop [coll coll]
  5.     (when-let [[first & rest] (seq coll)]
  6.       (let [val (fn first)]
  7.         (if (nil? val)
  8.           (recur rest)
  9.           (cons val rest))))))
  10.  
  11. (def inputs (atom ["/home/xgp/tmp/1.clj" "/home/xgp/tmp/2.clj"]))
  12.  
  13. (defn interested-line? [line]
  14.   true)
  15.  
  16. (defn read-next-line [inputs]
  17.   (dropping-transform (fn [input]
  18.                         (let [reader (if (string? input)
  19.                                        (io/reader input)
  20.                                        (first input))
  21.                               lines (dropping-transform (fn [line]
  22.                                                           (when (interested-line? line)
  23.                                                             line))
  24.                                                         (line-seq reader))]
  25.                           (if (seq lines)
  26.                             [reader lines]
  27.                             (do (.close reader)
  28.                                 nil))))
  29.                       inputs))
  30.  
  31. (loop []
  32.   (when-let [v (seq (swap! inputs read-next-line))]
  33.     (let [[[_ [line]]] v]
  34.       (println line)
  35.       (recur))))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top