package vals// Iterator wraps the Iterate method.typeIteratorinterface {// Iterate calls the passed function with each value within the receiver. // The iteration is aborted if the function returns false.Iterate(func(v interface{}) bool)}typecannotIteratestruct{ kindstring }func ( cannotIterate) () string { return"cannot iterate " + .kind }// CanIterate returns whether the value can be iterated. If CanIterate(v) is// true, calling Iterate(v, f) will not result in an error.func ( interface{}) bool {switch .(type) {caseIterator, string, List:returntrue }returnfalse}// Iterate iterates the supplied value, and calls the supplied function in each// of its elements. The function can return false to break the iteration. It is// implemented for the builtin type string, the List type, and types satisfying// the Iterator interface. For these types, it always returns a nil error. For// other types, it doesn't do anything and returns an error.func ( interface{}, func(interface{}) bool) error {switch v := .(type) {casestring:for , := range { := (string())if ! {break } }caseList:for := .Iterator(); .HasElem(); .Next() {if !(.Elem()) {break } }caseIterator: .Iterate()default:returncannotIterate{Kind()} }returnnil}// Collect collects all elements of an iterable value into a slice.func ( interface{}) ([]interface{}, error) {var []interface{}if := Len(); >= 0 { = make([]interface{}, 0, ) } := Iterate(, func( interface{}) bool { = append(, )returntrue })return , }
The pages are generated with Goldsv0.2.8-preview. (GOOS=darwin GOARCH=arm64)