mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 23:33:37 +00:00
6b21ad9922
Everywhere including examples, external interop APIs, bindings generators code and in other valuable places. A couple of `interface{}` usages are intentionally left in the CHANGELOG.md, documentation and tests.
29 lines
1.2 KiB
Go
29 lines
1.2 KiB
Go
/*
|
|
Package iterator provides functions to work with Neo iterators.
|
|
*/
|
|
package iterator
|
|
|
|
import "github.com/nspcc-dev/neo-go/pkg/interop/neogointernal"
|
|
|
|
// Iterator represents a Neo iterator, it's an opaque data structure that can
|
|
// be properly created by storage.Find. Iterators range over key-value pairs,
|
|
// so it's convenient to use them for maps. This structure is similar in
|
|
// function to Neo .net framework's Iterator.
|
|
type Iterator struct{}
|
|
|
|
// Next advances the iterator returning true if it was successful (and you
|
|
// can use Value to get value for slices or key-value pair for maps) and false
|
|
// otherwise (and there are no more elements in this Iterator). This function
|
|
// uses `System.Iterator.Next` syscall.
|
|
func Next(it Iterator) bool {
|
|
return neogointernal.Syscall1("System.Iterator.Next", it).(bool)
|
|
}
|
|
|
|
// Value returns iterator's current value. It's only valid to call after
|
|
// a successful Next call. This function uses `System.Iterator.Value` syscall.
|
|
// For slices, the result is just value.
|
|
// For maps, the result can be cast to a slice of 2 elements: a key and a value.
|
|
// For storage iterators, refer to `storage.FindFlags` documentation.
|
|
func Value(it Iterator) any {
|
|
return neogointernal.Syscall1("System.Iterator.Value", it)
|
|
}
|