MAP/ALL/ANY are replacing missing item value with previous item value
vlazar opened this issue · 2 comments
c = Dentaku::Calculator.new
# correct
c.evaluate!("MAP(items, i, i.value)", items: [{value: 1}, {value: nil}, {value: 2}, {value: nil}])
# => [1, nil, 2, nil]
# bug
c.evaluate!("MAP(items, i, i.value)", items: [{value: 1}, {}, {value: 2}, {}])
# => [1, 1, 2, 2]
MAPP/ALL/ANY share a very similar implementation, so ALL and ANY have the same issue of keeping a value from previous item if current item value is missing.
The context mutation bug is fixed in d77dd3b; however, it might not work as you want, because any item that does not have the key you're looking for will raise an unbound variable error.
@rubysolo Thank you for the fix!
The behavior makes more sense now. However as you pointed out it will now raise an unbound variable error on missing keys. I've been thinking about this distinction for quite a while now.
I think that in general I need a way to be able chose between a more strict behavior (the one with fix) and an old one where the outcome would be nil
in result instead of unbound variable exception.
I've opened a separate issue to discuss it: #236