diff --git a/README.md b/README.md index e0fcaaa..a29057a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,10 @@ More transducers and reducing functions for Clojure(script)! * in `net.cgrand.xforms.rfs`: `min`, `minimum`, `max`, `maximum`, `str`, `str!`, `avg`, `sd`, `last` and `some`. * in `net.cgrand.xforms.io`: `line-out` and `edn-out`. -*Transducing contexts*: `transjuxt` (for performing several transductions in a single pass), `into`, `count` and `some`. +*Transducing contexts*: + + * in `net.cgrand.xforms`: `transjuxt` (for performing several transductions in a single pass), `into`, `count` and `some`. + * in `net.cgrand.xforms.io`: `line-out` (3+ args) and `edn-out` (3+ args). *Reducible views* (in `net.cgrand.xforms.io`): `lines-in` and `edn-in`. @@ -26,7 +29,7 @@ More transducers and reducing functions for Clojure(script)! Add this dependency to your project: ```clj -[net.cgrand /xforms "0.10.1"] +[net.cgrand /xforms "0.10.2"] ``` ```clj diff --git a/project.clj b/project.clj index 261f1db..03ea792 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject net.cgrand/xforms "0.10.1" +(defproject net.cgrand/xforms "0.10.2" :description "Extra transducers for Clojure" :url "https://github.com/cgrand/xforms" :license {:name "Eclipse Public License" diff --git a/src/net/cgrand/xforms/io.clj b/src/net/cgrand/xforms/io.clj index 9c42416..8d1f6dd 100644 --- a/src/net/cgrand/xforms/io.clj +++ b/src/net/cgrand/xforms/io.clj @@ -33,13 +33,18 @@ state)))))))) (defn lines-out - "Reducing function that writes values serialized to its accumulator (a java.io.Writer). + "1-2 args: reducing function that writes values serialized to its accumulator (a java.io.Writer). + 3+ args: transducing context that writes transformed values to the specified output. The output is + coerced to a Writer by passing out and opts to clojure.java.io/writer. The output is automatically closed. Returns the writer." ([w] w) ([^java.io.Writer w line] (doto w (.write (str line)) - (.newLine)))) + (.newLine))) + ([out xform coll & opts] + (with-open [w (apply io/writer out opts)] + (transduce xform lines-out w coll)))) (defn edn-in "Returns a reducible view over the provided input. @@ -72,7 +77,9 @@ (recur state)))))))))))) (defn edn-out - "Reducing function that writes values serialized as EDN to its accumulator (a java.io.Writer). + "1-2 args: reducing function that writes values serialized as EDN to its accumulator (a java.io.Writer). + 3+ args: transducing context that writes transformed values to the specified output. The output is + coerced to a Writer by passing out and opts to clojure.java.io/writer. The output is automatically closed. Returns the writer." ([w] w) ([^java.io.Writer w x] @@ -83,4 +90,7 @@ *print-meta* false *print-readably* true] (prn x) - w))) \ No newline at end of file + w)) + ([out xform coll & opts] + (with-open [w (apply io/writer out opts)] + (transduce xform edn-out w coll)))) \ No newline at end of file