0

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

This works: empty {} #true

but this doesn't:

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

[{"foo"}, {"bar"}, {}, {}] |> map (-> console.log (empty it) ) #true true true true Is this a problem with empty?

Any help will be appreciated.

helb
  • 7,609
  • 8
  • 36
  • 58
muyueh
  • 1,018
  • 13
  • 16

2 Answers2

0

My current workaround is to implement my own empty:

empty = (obj)->
  Object.keys(obj).length is 0
muyueh
  • 1,018
  • 13
  • 16
0

You need to use the appropriate empty function for the type of input you are using, in this case, use Obj.empty. The empty you are using comes from List.empty. Using that on an object should probably be an error instead of what currently happens.

[{"foo"}, {"bar"}, {}, {}] |> filter Obj.empty
gkz
  • 416
  • 3
  • 5