Skip to content

Instantly share code, notes, and snippets.

@mohayonao
Last active December 27, 2015 10:09
Show Gist options
  • Save mohayonao/7309372 to your computer and use it in GitHub Desktop.
Save mohayonao/7309372 to your computer and use it in GitHub Desktop.
iterator
i = Iterator ->
x = 0
@yield x # 0
x += 10
@yield x # 10
x += 10
if no
@yield "skipped"
else if yes
@yield x
x += 10
@yield x # 30
i.next() #=> 0
i.next() #=> 10
i.next() #=> 20
i.next() #=> 30
i.next() #=> null
i = Iterator ->
[x] = []
[
=>
x = 0
@yield x
=>
x += 10
@yield x
=>
x += 10
if no
@yield "skipped"
else if yes
@yield x
=>
x += 10
@yield x
]
i.next() #=> 0
i.next() #=> 10
i.next() #=> 20
i.next() #=> 30
i.next() #=> null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment