Length from iterator?

Sometimes I found it useful to get the length and the last iterate, e.g. if the iterator does some numerical work until a convergence criteria holds.

So a generally useful function is:

    lastiterate(itr) = foldl((x, y) -> y, itr)

And then

julia> lastiterate('A':'Z')
'Z'

and

julia> lastiterate(enumerate('A':'Z'))
(26, 'Z')
1 Like