Idiomatic way to write Clojure code for repeatedly reading lines from the console?

后端 未结 3 1717
余生分开走
余生分开走 2021-02-06 00:06

Recently I was writing a little CLI script which needed to repeatedly read dates from the console (the number of dates to read was calculated and could be different each time).

3条回答
  •  遥遥无期
    2021-02-06 00:31

    You can do something like this:

    (defn read-dates [n] 
         (doall  (for [_ (range n)] (java.util.Date/parse (read-line)))))
    
    (def my-dates (read-dates 5)) ;Read 5 dates from console
    

提交回复
热议问题