0

这有效:
[1 to 10] |> filter (> 4) |> console.log #[ 5, 6, 7, 8, 9, 10 ]

这有效: empty {} #true

但这不是:

[{"foo"}, {"bar"}, {}, {}] |> filter empty |> console.log # [ { foo: 'foo' }, { bar: 'bar' }, {}, {} ]

[{"foo"}, {"bar"}, {}, {}] |> map (-> console.log (empty it) ) #true true true true 这是空的问题吗?

任何帮助将不胜感激。

4

2 回答 2

0

我目前的解决方法是实现我自己的empty

empty = (obj)->
  Object.keys(obj).length is 0
于 2014-03-11T08:12:19.870 回答
0

您需要为empty您正在使用的输入类型使用适当的函数,在这种情况下,使用Obj.empty. 您使用的empty来自List.empty. 在对象上使用它可能应该是一个错误,而不是当前发生的事情。

[{"foo"}, {"bar"}, {}, {}] |> filter Obj.empty
于 2014-03-18T08:20:46.177 回答