Last active
June 10, 2020 23:30
-
-
Save powerc9000/9dfffbf2d7cdd1335e588c7ec1623d2d to your computer and use it in GitHub Desktop.
This file contains 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
// This struct can be anything you want. It will just get passed to our iterator function for each iteration. | |
// Just an example. | |
MyCustomIterator :: struct { | |
data: []string //Can be any data | |
index: int, | |
length: int | |
} | |
iterate_my_type :: proc(it: ^MyCustomIterator) -> (value: string, index: int, ok: bool) { | |
ok = it.index + 1 == it.length; | |
value = data[it.index] | |
index = it.index; | |
it.index += 1; | |
} | |
proc_using_iterator :: proc() { | |
iterator : MyCustomIterator = {data=some_array_of_strings, len=10, index = 0} | |
for item in iterate_my_type(&iterator){ | |
// yadda yadda. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment