From: Brian H. <bri...@ql...> - 2003-05-26 23:17:00
|
On Mon, 26 May 2003, Manos Renieris wrote: > On Mon, May 26, 2003 at 05:51:36PM -0500, Brian Hurt wrote: > > > > The more I think about, the more I think the solution is to merge Stream > > and Enum, and create a best-of-breed interface (probably called > > ExtStream). IMHO, this api would: > > - have an exported next, like Stream > > - have an exported count, like Enum > > On streams generated from list's or files, count is not a sensible > operation, or am I mistaken? > From lists, it's an O(N) operation but easy enough (List.length). For any datastructure where traversing the elements is not destructive, count is also easily doable. But for files, "traversing the elements" is destructive- you read the file. And if the file really is the console and the user typing stuff in, you can't just rewind and reread the file either. At which point you need to create the interim list of objects. But you're right, count needs to be an optional thing. Brian |