Why does Incanter return number instead of sequence when result is one value?

亡梦爱人 提交于 2019-12-11 10:54:05

问题


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


回答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:

  • https://groups.google.com/forum/?fromgroups=#!topic/incanter/89RNomNMBWA


来源:https://stackoverflow.com/questions/16385215/why-does-incanter-return-number-instead-of-sequence-when-result-is-one-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!