Question

I am having an issue that can be reduced to the following problem: When the result of a query is one value, sel / $ returns a number, when it is more than one value, it is a sequence:

(with-data (to-dataset [[1 2] [3 4]])
    ($ :col-1))

yields (2 4), but

(with-data (to-dataset [[1 2]])
    ($ :col-1))

yields 2.

I would like it to be a sequence at all times, since I want to e. g. apply + to the sequence. I want to avoid checking for the type using (seq?). Any ideas? Is this behaviour of Incanter reasonable?

This is my workaround:

(let [seq-it (fn [a] (if (seq? a) a (list a)))]
  (with-data (to-dataset [[1 2]])
    (->> ($ :col-1) 
         (seq-it))))

which yields (2).

Was it helpful?

Solution

I believe this is a bug in Incanter (or you might regard it as a serious design flaw that should be fixed).

It is probably related to the issue discussed here, where 1x1 matrix results get converted to doubles:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top