Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Eve is based on pattern-matching and is set-oriented. So

  all-checked = [#todo completed: true]
would match each of the records with both topic: 'todo' and completed: true. And the following commit block would once per matching record. But what is desired here is one value for all the matching records (an "aggregate" in Eve lingo).

Personally I think we would be much better off with a dedicated aggregate function instead of using if/else here. And count (which is an aggregate function), should have a default value for when no records match. Then could get rid of the if/else there also, and have something like:

  all-checked = all[#todo completed: true]
  none-checked = none[#todo completed: true]
  todo-count = count[given: [#todo completed: false], default: 0]
Disclaimer: I'm just an Eve user/contributor


Thinking about it, it is possible that this proposal would not work, because in the nothing-matches cases then the function would not be executed at all... But maybe this could work, by widening the matching pattern.

  all-checked = all[in: [#todo], where: [completed: true] ]
  none-checked = none[in: [#todo], where: [completed: true] ]
  todo-count = count[in: [#todo], where: [completed: false], default: 0]




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: