You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Working with potentially infinite iterables and groupBy implies that we are not able to know how many groups of iterable will be produced. For example, we can infer that this expression:
range(0, Infinity).groupBy(e => e % 3)
just produces 3 groups ([0, 3, 6...], [1, 4, 7, ...] & [2, 5, 8, ...]), but we can not infer this for a generic function.
Then, I think that there are 2 approaches.
First approach:
constiterable=range(0,Infinity).groupBy(e=>e%3)constiterator=iterable[Symbol.iterator]()constfirstGroup=iterator.next().value// potentially [0, 3, 6, ...]constsecondGroup=iterator.next().value// potentially [1, 4, 7, ...]constthirdGroup=iterator.next().value// potentially [2, 5, 8, ...]constFourthGroup=iterator.next()// infinite loop because there are not another group and `range(0, Infinity)` never ends.
Second approach:
constiterable=range(0,Infinity).groupBy(e=>e%3)constiterator=iterable[Symbol.iterator]()constfirstGroup=iterator.next().value// potentially [0, 3, 6, ...]constsecondGroup=iterator.next().value// potentially [1, 4, 7, ...]constthirdGroup=iterator.next().value// potentially [2, 5, 8, ...]constFourthGroup=iterator.next()// returns lazy iterableconstFifthgroup=iterator.next()// returns lazy iterable// But then if we try to execute:constit=FourthGroup[Symbol.iterator]()it.next()// it produces an infinite loop because does not found any element that matches
Second approach is lazier than first approach. But first approach is more expected. For example, it look likes weird that happens this:
variterable=Iterum([1,6,3,4,8,3]).groupBy(e=>e%3)/* following the second approach it returns [ potentially [1, 4], potentially [6, 3, 3], potentially [8], potentially [], potentially [], potentially [], ...] */// then if we do:[...iterable]// it produces an infinite loop and maybe it is more expectable returning [Iterum([1, 4]), Iterum([6, 3, 3]), Iterum([8])]
If a
groupBy
method returns a lazy iterable of lazy iterables, it is possible call this method on potentially infinite iterable:The text was updated successfully, but these errors were encountered: