(defn get-doc-list [a-term]
(map #(Integer/parseInt %)(take-nth 3 (take (* 3 3)(rest (rest a-term))))))
This function works on small lists but returns and empty sequence on larger ones. What is the problem?
(defn get-doc-list [a-term]
(map #(Integer/parseInt %)(take-nth 3 (take (* 3 3)(rest (rest a-term))))))
This function works on small lists but returns and empty sequence on larger ones. What is the problem?
This is certainly an input issue, as your function will parse at most 3 integers:
user=> (get-doc-list (repeat "1"))
(1 1 1)
And only return empty sequence if less than 3 strings are supplied:
user=> (get-doc-list ["1" "1"])
()
And throw an exception if a non string is given:
user=> (get-doc-list [1 1 1])
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
I suggest checking what the input it "fails" with really is... maybe you are passing in something like [["1" "1" "1" ...]]
user=> (get-doc-list [["1" "1" "1"]])
()
This is a vector of vectors, as you can see nothing is processed so there is no error or sequence to generate.
The issue is your use of the take
function, which returns only the first n items of the collection. Regardless of how big a collection you pass get-doc-list
, only the first 9 get passed on to take-nth
.