jmakeig / iterant

Wraps any JavaScript iterable to provide a common set of chainable methods
https://jmakeig.github.io/iterant
Apache License 2.0
1 stars 0 forks source link

Extend with custom iterables #8

Closed jmakeig closed 8 years ago

jmakeig commented 8 years ago

Iterable is more like an interface. It should be possible for concrete instances to extend this with properties/methods that are specific to their own type, override existing implementations, or fallback to the built-in functionality.

For example, for a MarkLogic Sequence, the slice() implementation uses fn.subsequence() internally. How can we decouple this from the Iterable interface? The xpath() method is an extension to the Iterable interface and likely not germain to other Iterable instances.

Symbol.species might help here.

jmakeig commented 8 years ago

It won't be possible to cover every iterable in a single implementation. Rather Iterable should supply a default naïve implementation and then Take a look at an example inheritance technique.

function Iterable(iterable) { … }
Iterable.prototype = Object.assign({},
   { slice(start, end): { … } }
);
function SequenceIterable() { … }
SequenceIterable.prototype = Object.assign(
  Object.create(Iterable.prototype),
  {
    slice(start, end): {
      …
    }
  }
);
jmakeig commented 8 years ago

Need to update docs.

jmakeig commented 8 years ago

Closed in 1436ac234e7a807826d3cc810664b4b20a3bba56.