So, I think the main thing here is that doseq
returns nil
, not a list.
Perhaps something like this will get you started...
file.txt:
1|Xxx|info1|222-2222
2|Yyy|info2|333-3333
3|Zzz|info3|444-4444
Then, in the REPL:
user> (defn load-data
[filename]
(with-open [r (clojure.java.io/reader filename)]
(-> (for [line (line-seq r)]
(let [[id name info phone] (clojure.string/split line #"\|")]
[(Integer/parseInt id) name info phone]))
(doall))))
#'user/load-data
user> (load-data "file.txt")
([1 "Xxx" "info1" "222-2222"]
[2 "Yyy" "info2" "333-3333"]
[3 "Zzz" "info3" "444-4444"])
Notably, the doall
is necessary here, since for
returns a lazy sequence; without the doall
, with-open
will close the reader before anything is read.