Skip to content

Package iter provides primitives for walking arbitrary data structures.

License

Notifications You must be signed in to change notification settings

cstockton/go-iter

Repository files navigation

Go Package: iter

Go Report Card

Get:

go get -u github.com/cstockton/go-iter

Example:

func Example() {
	v := []interface{}{"a", "b", []string{"c", "d"}}
	err := iter.Walk(v, func(el iter.Pair) error {
		// check for errors
		if err := el.Err(); err != nil {
			return err
		}

		// Halt iteration by returning an error.
		if el.Depth() > 1 {
			return errors.New("Stopping this walk.")
		}

		fmt.Println(el)
		return nil
	})
	if err == nil {
		log.Fatal(err)
	}

	// Output:
	// Pair{(int) 0 => a (string)}
	// Pair{(int) 1 => b (string)}
}

About

Package iter provides primitives for walking arbitrary data structures.

Bugs and Patches

Feel free to report bugs and submit pull requests.

About

Package iter provides primitives for walking arbitrary data structures.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages