/go-iter

Package iter provides primitives for walking arbitrary data structures.

Primary LanguageGoMIT LicenseMIT

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.