0

I have data like that

tab = ({"123" data} {"456" data} ... 

(whatever, it is a lazy sequence of hashmaps).

I want to write it into an edn file line by line, so I did this

(map (fn[x] (spit "test.edn" x :append true)) tab)

The problem is that I would like to have this in the file :

{"123" data}
{"456" data}

But it seems to append like that

{"123" data}{"456" data}

Is there a way to solve this ? I guess I have to add "newline" but I don't know how to do it since inputs are not strings.

Thanks !

user229044
  • 232,980
  • 40
  • 330
  • 338
Joseph Yourine
  • 1,301
  • 1
  • 8
  • 18

2 Answers2

1

Sorry, I finally found it, hope it will help some people beauce I did not find it in the internet (I mean no simple answer).

(map (fn[x] (spit "test.edn" (str x "\n") :append true)) tab)

Good afternoon.

Joseph Yourine
  • 1,301
  • 1
  • 8
  • 18
1
(doseq [x tab]
  (spit "test.edn" (prn-str x) :append true))

So, for each item in tab, convert it to a readable string followed by a newline, then append that string to test.edn.

You should not use map for this for a couple of reasons:

  1. map is lazy and therefore will not print the entire sequence unless you force it
  2. map retains the head of the sequence, which would simply waste memory here
Sam Estep
  • 12,974
  • 2
  • 37
  • 75
  • Thanks ! Haven't tried yet because my thing is working but will have a look when my final program will work for improvement ! – Joseph Yourine Feb 19 '16 at 09:34