1

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).

0dB
  • 675
  • 5
  • 13

1 Answers1

1

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:

mikera
  • 105,238
  • 25
  • 256
  • 415
  • If this is a bug or design flaw, I could use (let [seq-it (fn [a] (if (seq? a) a (list a)))] (with-data (to-dataset [[1 2] [3 4]]) (->> ($ :col-1) (seq-it)))) – 0dB May 05 '13 at 14:29