Last active
August 8, 2018 01:01
-
-
Save antimon2/1fda74ae88f9178e4bdf5fa784e253aa to your computer and use it in GitHub Desktop.
Julia 0.7-DEV の新しい Iteration に触れてみた。 ref: https://qiita.com/antimon2/items/8b1a96d1370bb6252757
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for cw in Zundoko() | |
print(cw) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iter = Zundoko() | |
state = start(iter) | |
while !done(iter, state) | |
(cw, state) = next(iter, state) | |
print(cw) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iter = Zundoko() | |
_next = iterate(iter) | |
while _next !== nothing | |
(cw, state) = _next | |
print(cw) | |
_next = iterate(iter, state) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for line in iter | |
println(line) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_next = iterate(iter) | |
while _next !== nothing | |
(line, state) = _next | |
println(line) | |
_next = iterate(iter, state) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
state = start(iter) | |
while !done(iter, state) | |
(line, state) = next(iter, state) | |
println(line) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ZunDoko end | |
Base.start(::ZunDoko) = 0 | |
Base.done(::ZunDoko, i::Int) = i == 6 | |
function Base.next(::ZunDoko, i::Int) | |
if i == 5 | |
("キ・ヨ・シ!", 6) | |
elseif i == 4 | |
rand([("ズン", 4), ("ドコ", 5)]) | |
else | |
rand([("ズン", i + 1), ("ドコ", 0)]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ZunDoko end | |
function Base.iterate(::ZunDoko, i::Int = 0) | |
i == 6 && return nothing | |
if i == 5 | |
("キ・ヨ・シ!", 6) | |
elseif i == 4 | |
rand([("ズン", 4), ("ドコ", 5)]) | |
else | |
rand([("ズン", i + 1), ("ドコ", 0)]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment