>
> Is there any way to make it lazy to avoid the dreaded outOfMemoryError ?
> Or is it already lazy and I'm not seeing it / working with it properly?
>
It's already lazy. If you are experiencing an outOfMemoryError, make sure
you're not holding on to the head of the list.
line-seq, partition-by, filter, and map all return lazy sequences.
-Walter
On Friday, June 22, 2012 6:33:58 PM UTC-4, Joseph Guhlin wrote:
>
> Awesome, thank you so much.
>
> Is there any way to make it lazy to avoid the dreaded outOfMemoryError ?
> Or is it already lazy and I'm not seeing it / working with it properly?
>
> Best,
> --Joseph
>
> On Friday, June 22, 2012 7:30:28 AM UTC-5, Walter Tetzner wrote:
>>
>>
>>
>> On Friday, June 22, 2012 8:28:02 AM UTC-4, Walter Tetzner wrote:
>>>
>>>
>>> (defn read-records
>>> "Read the data from the given reader as a list of strings, where
>>> each string is made up of multiple lines, separated by // on it's own
>>> line."
>>> [reader]
>>> (->> (line-seq reader)
>>> (partition-by #{["//"]})
>>> (filter (comp not #{["//"]}))
>>> (map (partial apply str))))
>>>
>>
>> Actually, you want the new lines:
>>
>> (defn read-records
>> "Read the data from the given reader as a list of strings, where
>> each string is made up of multiple lines, separated by // on it's own
>> line."
>> [reader]
>> (->> (line-seq reader)
>> (partition-by #{["//"]})
>> (filter (comp not #{["//"]}))
>> (map (partial clojure.string/join "\n"))))
>>
>>
--
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