Closed stasm closed 6 years ago
After a bit more thinking about this, I think it's best to not tinker with the constructor logic. It's not something the builtin objects like Array
do.
Instead I suggest we add a static from()
method which takes an iterable, in which case it behaves the same as the constructor, or a CachedIterable
, in which case it just returns the same CachedIterable
it was passed, thus keeping its cached state.
In some cases, users might want to create a
Cached*Iterable
themselves and pass it into APIs which useCached*Iterable
behind the scenes. For instance, influent-react
theLocalization
class wraps the iterable of messages in aCachedAsyncIterable
. At the same time, the user offluent-react
might want to prefetch some contexts from that iterable before handing it off toLocalization
.