为什么当结果是一个值时,Incanter返回数字而不是序列? [英] Why does Incanter return number instead of sequence when result is one value?

查看:143
本文介绍了为什么当结果是一个值时,Incanter返回数字而不是序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,可以减少到以下问题:当查询的结果是一个值, sel / $ 返回一个数字,当多个值,它是一个序列:

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

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

产生2。



希望它是一个顺序在任何时候,因为我想e。 G。应用+到序列。我想避免检查类型使用(seq?)。有任何想法吗?这是Incanter的行为是否合理?



这是我的解决方法:

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


$ b

我相信这是Incanter中的一个错误(或者你可能认为它是一个错误)一个严重的设计缺陷应该固定)。



这可能与这里讨论的问题相关,其中1x1矩阵结果转换为双精度:




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

解决方案

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:

这篇关于为什么当结果是一个值时,Incanter返回数字而不是序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆