// Convert a []interface{} OR a map[string]interface{} to properly typed values
423109
func jsonParamsToArgsRPC(rpcFunc *RPCFunc, params json.RawMessage) ([]reflect.Value, error) {
	return jsonParamsToArgs(rpcFunc, params, 0)
}
1011924
func convert(t reflect.Type, value string) (reflect.Value, error) {
	if value == "" {
		return reflect.ValueOf(nil), nil
	}

	switch t.Kind() {
	case reflect.String:
		return reflect.ValueOf(value), nil
		// ptr.Elem()
		// ptr = reflect.ValueOf(value).Elem().Convert(reflect.String)
		// return reflect.ValueOf(value), nil
	case reflect.Int:
		return parseInt(value)
	case reflect.Bool:

		return parseBool(value)
	}

	return reflect.ValueOf(nil), conversionError(value, `unsupported `+t.Kind().String())
}
735629
func (v *Value) Interface() interface{} {
	if v.val.IsValid() {
		return v.val.Interface()
	}
	return nil
}
605044
func convertMap(in map[interface{}]interface{}) map[string]interface{} {
  rtn := make(map[string]interface{})
  for key, val := range in {
    // if the value is a map of interface interfaces
    // make sure to convert them as well    
    var newValue interface{}
    switch val.(type) {
      case []interface{}:
        newValue = convertArray(val.([]interface{}))
      case map[interface{}]interface{}:
        newValue = convertMap(val.(map[interface{}]interface{}))
      default:
        newValue = val
    }

    switch key.(type) {
    case string:
      rtn[key.(string)] = newValue
    }
  }

  return rtn  
}
697465
func MapKeyValues(keyvals []interface{}, fn func(interface{}, interface{}) (interface{}, interface{})) []interface{} {
	mappedKeyvals := make([]interface{}, len(keyvals))
	for i := 0; i < 2*(len(keyvals)/2); i += 2 {
		key := keyvals[i]
		val := keyvals[i+1]
		mappedKeyvals[i], mappedKeyvals[i+1] = fn(key, val)
	}
	return mappedKeyvals
}
1343091
func Values(in ...map[string]interface{}) ([]interface{}, error) {
	if len(in) == 0 {
		return nil, fmt.Errorf("need at least one argument")
	}
	values := []interface{}{}
	for _, m := range in {
		_, v := splitMap(m)
		values = append(values, v...)
	}
	return values, nil
}
1049168
func InterfaceArrayToStringArray(inArray []interface{}) ([]string, bool) {
	var outArray []string
	allConverted := true
	for _, item := range inArray {
		if istr, ok := item.(string); ok {
			outArray = append(outArray, istr)
		} else {
			allConverted = false
		}
	}
	return outArray, allConverted
}
824951
func SimpleType_Values() []SimpleType {
	return []SimpleType{
		SimpleTypeBool,
		SimpleTypeByte,
		SimpleTypeInt8,
		SimpleTypeInt16,
		SimpleTypeInt32,
		SimpleTypeInt64,
		SimpleTypeFloat64,
		SimpleTypeString,
		SimpleTypeStructEmpty,
	}
}
808709
func TryToSliceValue(i interface{}, t reflect.Type) (slice reflect.Value, err error) {
	if s, ok := i.(string); ok {
		if s == "" {
			i = []string(nil)
		} else {
			i = strings.Split(s, ",")
		}
	}

	v := reflect.ValueOf(i)
	if v.Kind() != reflect.Slice {
		err = castError(i, "[]"+t.String())
		return
	}

	if t == v.Type().Elem() {
		return v, nil
	}

	length := v.Len()
	slice = reflect.MakeSlice(reflect.SliceOf(t), length, length)
	for k := 0; k < length; k++ {
		var value reflect.Value
		value, err = TryToValue(v.Index(k).Interface(), t)
		if err != nil {
			return
		}
		slice.Index(k).Set(value)
	}
	return slice, nil
}
814167
func CastInterfaceToInterfaceSlice(slice interface{}) ([]interface{}, error) {
	s := reflect.ValueOf(slice)
	if s.Kind() != reflect.Slice {
		return []interface{}{}, fmt.Errorf("Input is not a slice: %#v", slice)
	}

	ret := make([]interface{}, s.Len())

	for i := 0; i < s.Len(); i++ {
		ret[i] = s.Index(i).Interface()
	}

	return ret, nil
}
1356287
func Interfaces(in interface{}) []interface{} {
	val := reflect.ValueOf(in)
	length := val.Len()
	results := make([]interface{}, length)
	for i := 0; i < length; i++ {
		elemVal := val.Index(i)
		results[i] = elemVal.Interface()
	}
	return results
}
271842
func convertArgs(args ...interface{}) []interface{} {
	newArgs := []interface{}{}
	for _, arg := range args {
		v := ValueOf(arg)
		newArgs = append(newArgs, v.internal())
	}
	return newArgs
}
412024
func Keys(m interface{}) []string {
	var list []string

	v := reflect.ValueOf(m)
	if v.Kind() == reflect.Map {
		for _, x := range v.MapKeys() {
			list = append(list, fmt.Sprintf("%s", x))
		}
	}

	return list
}
297566
func ReturnTypes(t interface{}) []string {
	if reflect.TypeOf(t).Kind() != reflect.Func {
		// Invalid provide, will be logged as an error.
		return []string{}
	}

	rtypes := []string{}
	ft := reflect.ValueOf(t).Type()

	for i := 0; i < ft.NumOut(); i++ {
		t := ft.Out(i)

		traverseOuts(key{t: t}, func(s string) {
			rtypes = append(rtypes, s)
		})
	}

	return rtypes
}
1042528
func (g *Generator) ConvertType(from, to string) {
	g.typeConversions[from] = to
}
1161134
func InterfaceToSliceOfStrings(v interface{}) []string {
	if v == nil {
		return nil
	}
	var sl []string
	switch reflect.TypeOf(v).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(v)
		sl = make([]string, s.Len(), s.Len())
		for i := 0; i < s.Len(); i++ {
			sl[i] = s.Index(i).Interface().(string)
		}
	case reflect.String:
		sl = append(sl, reflect.ValueOf(v).Interface().(string))
	default:
		return nil
	}
	return sl
}
954669
func Values(e error) map[interface{}]interface{} {
	if e == nil {
		return nil
	}
	var values map[interface{}]interface{}
	for {
		w, ok := e.(*merryErr)
		if !ok {
			return values
		}
		if values == nil {
			values = make(map[interface{}]interface{}, 1)
		}
		if _, ok := values[w.key]; !ok {
			values[w.key] = w.value
		}
		e = w.err
	}
}