benji6/imlazy

equals is not enough lazy

xgbuils opened this issue · 4 comments

It is obvious that is imposible to avoid this infinite loop

const list1 = drop(1, range(0, Infinity))
const list2 = drop(1, range(0, Infinity))
equals(list1, list2) // infinite loop

But what about that?

const naturals = range(0, Infinity)
equals(naturals, assoc(2, 42, naturals)) // It should return false

I think that it could return false using finite time.

Cheers!

includes has the same caveat.

Very good point on equals - I will investigate! Do you have an example with includes? There's a test case with an infinite iterable here which passes https://github.com/benji6/imlazy/blob/master/test/includes.js#L8

Of course, I mean includes uses equals. Then it seems that

const naturals = range(0, Infinity)
includes(naturals, [assoc(2, 42, naturals)]) 

could have the same problem.

ah yes! good point :)