You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: scope.go
    path of file: ./repos/juju/cmd/juju/waitfor/query
    
    the code of the file until where you have to start completion: // Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package query

import (
	"fmt"
	"reflect"
	"sort"
	"strconv"
	"strings"

	"github.com/juju/errors"
)

// GlobalFuncScope defines a set of builtin functions that can be executed based
// on a set of arguments.
type GlobalFuncScope struct {
	scope Scope
	funcs map[string]any
}

// NewGlobalFuncScope creates a new scope for executing functions.
func NewGlobalFuncScope(scope Scope) *GlobalFuncScope {
	return &GlobalFuncScope{
		scope: scope,
		funcs: map[string]any{
			"len": func(v any) (int, error) {
				val := reflect.ValueOf(v)
				switch val.Kind() {
				case reflect.Map, reflect.Slice, reflect.String:
					return val.Len(), nil
				default:
					if box, ok := v.(Box); ok {
						var num int
						ForEach(box, func(value any) bool {
							num++
							return true
						})
						return num, nil
					}
					return -1, RuntimeErrorf("unexpected type %T passed to len", v)
				}
			},
			"print": func(v any) (any, error) {
				fmt.Printf("%+v\n", v)
				return v, nil
			},
			"forEach": func(values, expr any) (any, error) {
				scopes, ok := values.(Box)
				if !ok {
					return nil, RuntimeErrorf("unexpected lambda values %T", values)
				}
				lambda, ok := expr.(*BoxLambda)
				if !ok {
					return nil, RuntimeErrorf("unexpected lambda %T", expr)
				}

				var (
					err    error
					called bool
					result = true
				)
				ForEach(scopes, func(value any) bool {
					called = true

					nestedScope, ok := value.(Scope)
					if !ok {
						err = RuntimeErrorf("unexpected scope type %T", value)
						return false
					}

					namedScope := MakeNestedScope(scope)
					namedScope.SetScope(lambda.ArgName(), nestedScope)

					var results []Box
					results, err = lambda.Call(namedScope)
					if err != nil {
						return false
					}
					var lambdaResult bool
					for _, result := range results {
						lambdaResult = !result.IsZero()
					}
					result = result && lambdaResult
					return result
				})
				if err != nil {
					return nil, errors.Trace(err)
				}
				if !called {
					return false, nil
				}
				return result, nil
    
func NewGlobalFuncScope(scope Scope) *GlobalFuncScope {
	return &GlobalFuncScope{
		scope: scope,
		funcs: map[string]any{
			"len": func(v any) (int, error) {
				val := reflect.ValueOf(v)
				switch val.Kind() {
				case reflect.Map, reflect.Slice, reflect.String:
					return val.Len(), nil
				default:
					if box, ok := v.(Box); ok {
						var num int
						ForEach(box, func(value any) bool {
							num++
							return true
						})
						return num, nil
					}
					return -1, RuntimeErrorf("unexpected type %T passed to len", v)
				}
			},
			"print": func(v any) (any, error) {
				fmt.Printf("%+v\n", v)
				return v, nil
			},
			"forEach": func(values, expr any) (any, error) {
				scopes, ok := values.(Box)
				if !ok {
					return nil, RuntimeErrorf("unexpected lambda values %T", values)
				}
				lambda, ok := expr.(*BoxLambda)
				if !ok {
					return nil, RuntimeErrorf("unexpected lambda %T", expr)
				}

				var (
					err    error
					called bool
					result = true
				)
				ForEach(scopes, func(value any) bool {
					called = true

					nestedScope, ok := value.(Scope)
					if !ok {
						err = RuntimeErrorf("unexpected scope type %T", value)
						return false
					}

					namedScope := MakeNestedScope(scope)
					namedScope.SetScope(lambda.ArgName(), nestedScope)

					var results []Box
					results, err = lambda.Call(namedScope)
					if err != nil {
						return false
					}
					var lambdaResult bool
					for _, result := range results {
						lambdaResult = !result.IsZero()
					}
					result = result && lambdaResult
					return result
				})
				if err != nil {
					return nil, errors.Trace(err)
				}
				if !called {
					return false, nil
				}
				return result, nil
			},
			"startsWith": func(v, prefix any) (bool, error) {
				if _, ok := prefix.(string); !ok {
					return false, RuntimeErrorf("requires string to be passed to startsWith, got %T", prefix)
				}

				val := reflect.ValueOf(v)
				switch val.Kind() {
				case reflect.String:
					return strings.HasPrefix(val.String(), prefix.(string)), nil
				default:
					return false, RuntimeErrorf("unexpected type %T passed to startsWith", v)
				}
			},
			"endsWith": func(v, suffix any) (bool, error) {
				if _, ok := suffix.(string); !ok {
					return false, RuntimeErrorf("requires string to be passed to endsWith, got %T", suffix)
				}

				val := reflect.ValueOf(v)
				switch val.Kind() {
				case reflect.String:
					return strings.HasSuffix(val.String(), suffix.(string)), nil
				default:
					return false, RuntimeErrorf("unexpected type %T passed to endsWith", v)
				}
			},
			"int": func(v any) (int, error) {
				val := reflect.ValueOf(v)
				switch val.Kind() {
				case reflect.String:
					return strconv.Atoi(val.String())
				default:
					return -1, RuntimeErrorf("unexpected type %T passed to int", v)
				}
			},
		},
	}
}