yes, i'm about to do it for arrays (i don't care about performance right now, but i want to implement read with type conversion and so need the types).
On Monday, 9 November 2015 11:20:47 UTC-3, Yichao Yu wrote: > > On Mon, Nov 9, 2015 at 8:04 AM, andrew cooke <and...@acooke.org > <javascript:>> wrote: > > > > https://github.com/andrewcooke/StatefulIterators.jl > > FYI, one way to make this more efficient is to parametrize the > iterator. You could easily do this for Array's. In the more general > case, you needs type inference to get the type right for a > non-type-stable iterator (iterator with a type unstable index...) but > it's generally a bad idea to write code that calls type inference > directly. > > > > > > > On Monday, 9 November 2015 06:24:14 UTC-3, andrew cooke wrote: > >> > >> thanks! > >> > >> On Sunday, 8 November 2015 22:40:53 UTC-3, Yichao Yu wrote: > >>> > >>> On Sun, Nov 8, 2015 at 8:11 PM, andrew cooke <and...@acooke.org> > wrote: > >>> > I'd like to be able to use take() and all the other iterator tools > with > >>> > a > >>> > stream of data backed by an array (or string). > >>> > > >>> > By that I mean I'd like to be able to do something like: > >>> > > >>> >> stream = XXX([1,2,3,4,5]) > >>> >> collect(take(stream, 3)) > >>> > [1,2,3] > >>> >> collect(take(stream, 2)) > >>> > [4,5] > >>> > > >>> > Is this possible? I can find heavyweight looking streams for IO, > and I > >>> > can > >>> > find lightweight iterables without state. But I can't seem to find > the > >>> > particular mix described above. > >>> > >>> Jeff's conclusion @ JuliaCon is that it seems impossible to implement > >>> this (stateful iterator) currently in a generic and performant way so > >>> I doubt you will find it in a generic iterator library (that works not > >>> only on arrays). A version that works only on Arrays should be simple > >>> enough to implement and doesn't sound useful enough to be in an > >>> exported API so I guess you probably should just implement your own. > >>> > >>> Ref > >>> > https://groups.google.com/forum/?fromgroups=#!searchin/julia-users/iterator/julia-users/t4ZieI2_iwI/3NTw1k406qkJ > > >>> > >>> > > >>> > (I think I can see how to write it myself; I'm asking if it already > >>> > exists - > >>> > seems like it should, but I can't find the right words to search > for). > >>> > > >>> > Thanks, > >>> > Andrew > >>> > >