> > I can see that there are some functions listed under the Iteration 
> section 
> > but it does not seem to be the full story. 
> > For example mapreduce works on iterable types (nice) but it seems that 
> the 
> > length function is not defined on iterables. Why is it so? 
>
> Iterables can be of infinite length.  For an infinite one a `length` 
> function would just hang.  Thus it is probably not a good idea. 
>

Well, if you collect countfrom(), you do not terminate. It is expected. 
`length` is not the only function that tries to get to the end of the 
iterable.

Interestingly, the enumerate function works on iterables but since length 
is not defined in general for iterables, we can't do much with the 
resulting Enumerate object. In particular, we are not guaranteed that we 
can collect it.

     julia> type Iterable x::Float64 end ;
     Base.start(x::Iterable) = 0;
     Base.next(x::Iterable, state) = (0,state+1);
     Base.done(x::Iterable, state) = true;
     strange = enumerate(Iterable(0.0));      # strange can't be collected. 
It can be taken though.
     typeof(strange)
     
    =>  Enumerate{Iterable}

Reply via email to