I have the following input:
(def nums [123456789012 123456789012])
I'd like the following output:
[[1234 5678 9012] [1234 5678 9012]]
*note both of these sequence contain numbers not strings...
I figured this would be really simple by doing the following:
- Convert each entry into a String
- Partition each string by 4
- Convert each partition back into an integer
Here is my failed attempt:
(defn split-nums [nums factor]
(map
#(map
(fn [x] (Integer/valueOf (str x)))
(partition factor (str %)))
nums))
(println (split-nums nums, 4))
When I run this I get the following error:
Caused by: java.lang.NumberFormatException: For input string: "clojure.lang.LazySeq@4834333c"
Which tells me I am dealing with a lazy sequence that I need to force evaluation on but when I try to (str (doall x)) I get the same result.
So clojure experts where am I going wrong? Is this a good approach? BTW. I've just started to learn clojure so I'm certainly not an expert.