Skip to content Skip to sidebar Skip to footer

How To Extend Iterableiterator In Typescript

I am trying to extend Iterable with a where method, similar to C# Enumerable.where(). Extending the Array prototype is easy, however I am struggling to find how to extend an Iterab

Solution 1:

You can extend the IteratorPrototype in which case your method will work with built-in Iterators like array.keys() or star functions, but not Iterables like arrays.

As you correctly said, there's no way to extend Iterable because no such thing exists at run time. Generally speaking, a more common practice is to design your own "monad" instead of extending built-in prototypes:

result= Enumerable(someIterable)
    .where(...)
    .map(...)
    .etc(...)
    .toList()

Post a Comment for "How To Extend Iterableiterator In Typescript"