rdfjs / dataset-spec

RDF/JS: Dataset specification 1.0 – This specification provides a definition how to store multiple quads in a so-called dataset.
https://rdf.js.org/dataset-spec/
6 stars 5 forks source link

Remove `every`, `some` and `forEach` #63

Closed blake-regalia closed 3 years ago

blake-regalia commented 3 years ago

I would suggest we remove these methods and instead promote the use of iterable<Quad> whenever possible. I also believe that Arrays are one dimensional and iterating a dataset one quad at a time has limited practicality. Quad datasets may have internal indexes that provide much better/faster means of testing for the presence of a triple, for example in the case of some.

I also wonder about map and reduce; but let's see where this discussion goes.

bergos commented 3 years ago

Not every callback function can be replaced with a match. Using the methods in the right way is important. And, yes, all of the mentioned methods can be replaced with iterable<Quad>, but we designed the DatasetCore interface to have the bare minimum to build other stuff on top. The Dataset interface should have convenient methods for functional programming. Here a simple example that would be way more complex using only iterable<Quad>:

function greaterThan (value) {
  return q => parseFloat(q.object.value) > value
}

if (dataset.match(subject, property).some(greaterThan(10)) {
}

I see your concerns, but removing methods that are useful in the proper context is not the solution. Having a primer document would be the better option.

blake-regalia commented 3 years ago

I do believe that using iterables over callbacks provides much more flexibility in general, especially when the callback return types are void or boolean. I only wondered about trying to simplify the interface, but if these methods are useful to some then I'm happy to keep them.