Thanks - I thought doall was probably better than mapv. Incidentally, doseq won't work - if the 5th result throws an exception during parsing, results 1-4 will still be saved, whereas I want the whole operation to abort without saving anything.
- Korny On 4 May 2013 19:38, Timo Mihaljov <[email protected]> wrote: > On 04.05.2013 12:16, Korny Sietsma wrote: > > What's the idiomatic way to avoid this? The options seem to be either > > to use > > (doall (map parse-record records)) > > or (mapv parse-record records) > > > > Is either of these better? The latter is simpler, the former (to me) > > expresses that you are deliberately forcing non-laziness. Or is there > > some other alternative? > > `doall` is idiomatic. As you said, `mapv` tells the reader that you need > the result to be a vector (you don't) while leaving implicit the fact > that you want to force the evaluation of the sequence, so it's confusing > in two ways. > > If you don't care about the return values of the `save-result!` calls, > the best way is to use `doseq` to iterate over the records: > > (defn parse-and-store [raw-data] > (try > (save-audit-data! raw-data) > (let [records (split-records raw-data) > results (map parse-record records)] > (doseq [result results] > (save-result! result))) > (catch Exception e > (save-error-data! raw-data e)))) > > -- > Timo > > -- > -- > 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/groups/opt_out. > > > -- Kornelis Sietsma korny at my surname dot com http://korny.info .fnord { display: none !important; } -- -- 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/groups/opt_out.
