er, s/(comp val)/val

On Sat Feb 14 2015 at 12:17:18 AM Michael Blume <[email protected]>
wrote:

> For minimal change to the presented code, what about
>
> (defprotocol appendable (append-to [this ^StringBuilder sb]))
>
> (extend-protocol appendable
>   String
>   (append-to [this ^StringBuilder sb] (.append sb this))
>   clojure.lang.IFn
>   (append-to [this ^StringBuilder sb] (this sb))
>   Object
>   (append-to [this ^StringBuilder sb] (.append sb (str this))))
>
> (defn final-str [a]
>   (let [sb (StringBuilder.)]
>     (append-to a sb)
>     (str sb)))
>
> (defn par-join [sep xs]
>   (fn [sb]
>     (when-let [xs (seq xs)]
>       (append-to (first xs) sb)
>       (doseq [x (next xs)]
>         (append-to sep sb)
>         (append-to x sb)))))
>
> (let [f #(->> % (map (comp val)) (par-join ","))]
>   (->> data-struct
>     (map f)
>     (par-join "\n")
>     final-str))
>
> Which winds up taking about a second and only creates one StringBuilder.
>
>
>
> On Fri Feb 13 2015 at 8:02:27 PM Andy Chambers <[email protected]>
> wrote:
>
>> Is there a reason you're collecting the result into a string rather than
>> just writing out to a file?
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to