//Function checks if the document exists and returns error if it does not
960497
func (doc *Document) Exists() ([]byte, error) {
	// Use the get operation to get it.
	body, err := doc.Db.Req.Get(doc.Id, nil)

	if err != nil {
		return nil, err
	} else {
		result := &struct {
			Error string `json:"error"`
			Ok    bool   `json:"ok"`
			Id    string `json:"_id"`
			Rev   string `json:"_rev"`
		}{}
		err = json.Unmarshal(body, result)
		if err != nil {
			return nil, err
		}

		if result.Error != "" {
			return nil, errors.New(result.Error)
		}
		doc.Id = result.Id
		doc.Rev = result.Rev
	}
	return body, nil
}
1064850
func (nsRefcounts_) exists(coll mongo.Collection, key string) (bool, error) {
	count, err := coll.FindId(key).Count()
	if err != nil {
		return false, errors.Trace(err)
	}
	return count != 0, nil
}
52214
func (s *Selection) IsFunction(f func(int, *Selection) bool) bool {
	return s.FilterFunction(f).Length() > 0
}
834523
func (t Result) Exists() bool {
	return t.Type != Null || len(t.Raw) != 0
}
1259234
func findFunction(name string) (reflect.Value, bool) {
	if fn := builtinFuncs[name]; fn.IsValid() {
		return fn, true
	}
	return reflect.Value{}, false
}
1278495
func IsDocument(buf []byte) bool {
	kind, _ := Document(buf)
	return kind != types.Unknown
}
149805
func (fac FileAvailableCheck) Check() (warnings, errorList []error) {
	klog.V(1).Infof("validating the existence of file %s", fac.Path)
	errorList = []error{}
	if _, err := os.Stat(fac.Path); err == nil {
		errorList = append(errorList, errors.Errorf("%s already exists", fac.Path))
	}
	return nil, errorList
}
796050
func (e *Element) IsDocument() (bool, error) {
	e.lock.RLock()
	defer e.lock.RUnlock()

	if !e.ready {
		return false, &ElementNotReadyErr{}
	}
	return (e.nodeType == int(DOCUMENT_NODE)), nil
}
530345
func (s *Adaptor) Function(name string, args string) (val int, err error) {
	params := url.Values{
		"args":         {args},
		"access_token": {s.AccessToken},
	}

	url := fmt.Sprintf("%s/%s", s.deviceURL(), name)
	resp, err := s.request("POST", url, params)

	if err != nil {
		return -1, err
	}

	val = int(resp["return_value"].(float64))
	return
}
948834
func (e Error) If(fn func(error)) {
	if e.Present() {
		fn(*e.value)
	}
}
882758
func AssertFunction(v Value) (Callable, bool) {
	if obj, ok := v.(*Object); ok {
		if f, ok := obj.self.assertCallable(); ok {
			return func(this Value, args ...Value) (ret Value, err error) {
				defer func() {
					if x := recover(); x != nil {
						if ex, ok := x.(*InterruptedError); ok {
							err = ex
						} else {
							panic(x)
						}
					}
				}()
				ex := obj.runtime.vm.try(func() {
					ret = f(FunctionCall{
						This:      this,
						Arguments: args,
					})
				})
				if ex != nil {
					err = ex
				}
				obj.runtime.vm.clearStack()
				return
			}, true
		}
	}
	return nil, false
}
1221805
func checkfile(fname string) (exists bool) {
  _, err := os.Stat(fname)
  if err == nil {
    exists = true
  } else if ! os.IsNotExist(err) {
    glog.Fatal(err)
  }
  return
}
682226
func Any(err error, fn func(error) bool) (any bool) {
	Walk(err, func(err error) bool {
		any = fn(err)
		return !any
	})
	return
}
56147
func IsFunc(kindable interface {
	Kind() reflect.Kind
}) bool {
	return kindable.Kind() == reflect.Func
}
482775
func (d *Document) Validate(r *http.Request, isResponse bool) *Error {

	// if sending a response, we must have a valid HTTP status at the very least
	// to send
	if isResponse && d.Status < 100 || d.Status > 600 {
		return ISE("Response HTTP Status is outside of valid range")
	}

	// There are certain cases such as HTTP 204 that send without a payload,
	// this is the short circuit to make sure we don't false alarm on those cases
	if d.empty {
		return nil
	}

	// if we have errors, and they have been added in a way that does not trigger
	// error mode, set it now so we perform the proper validations.
	if d.HasErrors() && d.Mode != ErrorMode {
		d.Mode = ErrorMode
	}

	switch d.Mode {
	case ErrorMode:
		if d.HasData() {
			return ISE("Attempting to respond with 'data' in an error response")
		}
	case ObjectMode:
		if d.HasData() && len(d.Data) > 1 {
			return ISE("Cannot set more than one data object in 'ObjectMode'")
		}
	case ListMode:
		if !d.HasErrors() && d.Data == nil {
			return ISE("Data cannot be nil in 'ListMode', use empty array")
		}
	}

	if !d.HasData() && d.Included != nil {
		return ISE("'included' should only be set for a response if 'data' is as well")
	}

	err := d.Data.Validate(r, isResponse)
	if err != nil {
		return err
	}

	err = d.Errors.Validate(r, isResponse)
	if err != nil {
		return err
	}

	d.validated = true

	return nil
}
913560
func Exists(args ...string) bool {
	if _, err := Raw(append([]string{"-C"}, args...)...); err != nil {
		return false
	}
	return true
}
644288
func (i Int32) If(fn func(int32)) {
	if i.Present() {
		fn(*i.value)
	}
}