|
1 | 1 | (ns parkour.util
|
2 | 2 | (:require [clojure.edn :as edn]
|
3 | 3 | [clojure.java.io :as io])
|
4 |
| - (:import [java.io PushbackReader Writer] |
| 4 | + (:import [java.io PushbackReader Writer ObjectInputStream ObjectOutputStream] |
5 | 5 | [clojure.lang IPending]))
|
6 | 6 |
|
7 | 7 | (defmacro ignore-errors
|
@@ -35,6 +35,16 @@ already an instance of `c`."
|
35 | 35 | "Return a new map made by mapping `f` over the values of `m`."
|
36 | 36 | [f m] (into {} (map (fn [[k v]] [k (f v)]) m)))
|
37 | 37 |
|
| 38 | +(defn realized-seq |
| 39 | + "Seq of only the already-realized portion of `coll`." |
| 40 | + [coll] |
| 41 | + (if-not (instance? IPending coll) |
| 42 | + (seq coll) |
| 43 | + (lazy-seq |
| 44 | + (if (realized? coll) |
| 45 | + (cons (first coll) |
| 46 | + (realized-seq (rest coll))))))) |
| 47 | + |
38 | 48 | (defn var-str
|
39 | 49 | "String fully-qualified name of a var."
|
40 | 50 | [v] (subs (pr-str v) 2))
|
@@ -104,12 +114,14 @@ already an instance of `c`."
|
104 | 114 | (with-open [f (PushbackReader. (apply io/reader f opts))]
|
105 | 115 | (edn/read {:readers *data-readers*} f)))
|
106 | 116 |
|
107 |
| -(defn realized-seq |
108 |
| - "Seq of only the already-realized portion of `coll`." |
109 |
| - [coll] |
110 |
| - (if-not (instance? IPending coll) |
111 |
| - (seq coll) |
112 |
| - (lazy-seq |
113 |
| - (if (realized? coll) |
114 |
| - (cons (first coll) |
115 |
| - (realized-seq (rest coll))))))) |
| 117 | +(defn jser-spit |
| 118 | + "Like `split`, but emits `content` to `f` via Java serialization." |
| 119 | + [f content & opts] |
| 120 | + (with-open [oos (ObjectOutputStream. (apply io/output-stream f opts))] |
| 121 | + (.writeObject oos content))) |
| 122 | + |
| 123 | +(defn jser-slurp |
| 124 | + "Like `slurp`, but reads content from `f` via Java serialization." |
| 125 | + [f & opts] |
| 126 | + (with-open [ois (ObjectInputStream. (apply io/input-stream f opts))] |
| 127 | + (.readObject ois))) |
0 commit comments