Julia iteration: onset, then, side effects

Iteration in Julia can be achieved for certain new types of iteration by implementing an interface which has 3 functions: start, next,done

I do not see an exclamation mark at the end of these functions, so from my understanding of julia naming conventions, these 3 functions should not change their arguments. In particular, these two loops should give the same output.

state = start(iter)
while !done(iter, state)
    (i, state) = next(iter, state)
    @show i
end


state = start(iter)
while !done(iter, state)
    (other_i, other_state) = next(iter, state)
    (i, state) = next(iter, state)
    @show i
end

Am I really wrong? I ask because I came across some iterators in julia's external packages without respecting this.

+4
source share
2 answers

, ( ). , . Base.Task, ( produce):

julia> collect(@async for i = 1:10
       produce(i)
       end)
10-element Array{Int64,1}:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10

, , (, , , , ). , - ( , , , ).

+7

, , , , .

, ! ,

ProgressMeter, !(), -,

( , - ), , , ,

TL;DR , , , , , , Essentials

( , , )

+3

Source: https://habr.com/ru/post/1652690/


All Articles