From: Nicolas C. <war...@fr...> - 2003-06-02 02:52:22
|
> Sorry, forgot to mention: the default has_next calls count() and compares > it against 0. Which means only in places where count() would be > signifigantly more expensive than has_next() do we need to (or can) supply > a seperate has_next(). Thanks Brian, I already had some thoughs about adding this has_next function , which can be useful. But we can't rewrite fold/iter using has_next because, has you mentionned, the default has_next will test count > 0 and the default count will force the enumeration of the data structure, resulting the building of an intermediate list, which is what we actually don't want to do. Seen like this, the has_next should be only used on the user side, and could be implemented by : let has_next t = t.count() > 0 with some documentation telling that it can be pretty ineficient (the first call only). Of course we could add the has_next function as a parameter to make but : - when we call make, we usually have a good count , so testing count > 0 is not so costly - when we don't call make (call from) we don't have a count... I can see few samples when we can peek data (without actually reading it) to see if there is some available, but I'm not sure they're worth it. - as the next function is returning a 'a option (and I still think that's the best way of doing it) the user will not need an has_next to loop. Nicolas Cannasse |