Skip to content

Instantly share code, notes, and snippets.

@powerc9000
Last active June 10, 2020 23:30
Show Gist options
  • Save powerc9000/9dfffbf2d7cdd1335e588c7ec1623d2d to your computer and use it in GitHub Desktop.
Save powerc9000/9dfffbf2d7cdd1335e588c7ec1623d2d to your computer and use it in GitHub Desktop.
// 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