// A function to turn a map into a PairList, then sort and return it.
550378
func sortMapByValue(m map[string]int) PairList {
	p := make(PairList, len(m))
	i := 0
	for k, v := range m {
		p[i] = Pair{k, v}
		i++
	}
	sort.Sort(p)
	return p
}
1035567
func sortParameters(params map[string]string, format string) []string {
	// sort by key
	keys := make([]string, len(params))
	i := 0
	for key := range params {
		keys[i] = key
		i++
	}
	sort.Strings(keys)
	// parameter join
	pairs := make([]string, len(params))
	for i, key := range keys {
		pairs[i] = fmt.Sprintf(format, key, params[key])
	}
	return pairs
}
902119
func FormatOrderedMap(keys []string, values []string) string {
	var buf bytes.Buffer
	started := false
	for i, val := range values {
		key := keys[i]
		if started {
			buf.WriteString(MapSeparator)
		}
		buf.WriteString(key)
		buf.WriteString(MapEquals)
		buf.WriteString(val)
		started = true
	}
	return buf.String()
}
614720
func (opts *ListOpts) GetMap() map[string]struct{} {
	ret := make(map[string]struct{})
	for _, k := range *opts.values {
		ret[k] = struct{}{}
	}
	return ret
}
1313813
func convertMap(m map[string]string) map[string]interface{} {
	c := make(map[string]interface{}, len(m))
	for k, v := range m {
		c[k] = v
	}
	return c
}
1290300
func reverseSortMapByValue(m map[string]int) pairList {
	p := make(pairList, len(m))
	i := 0
	for k, v := range m {
		p[i] = pair{k, v}
		i = i + 1
	}
	sort.Sort(sort.Reverse(p))
	return p
}
164457
func (c *Scratch) GetSortedMapValues(key string) interface{} {
	c.mu.RLock()

	if c.values[key] == nil {
		c.mu.RUnlock()
		return nil
	}

	unsortedMap := c.values[key].(map[string]interface{})
	c.mu.RUnlock()
	var keys []string
	for mapKey := range unsortedMap {
		keys = append(keys, mapKey)
	}

	sort.Strings(keys)

	sortedArray := make([]interface{}, len(unsortedMap))
	for i, mapKey := range keys {
		sortedArray[i] = unsortedMap[mapKey]
	}

	return sortedArray
}
755010
func PlainStringMapToFormattedJSON(plainmap map[string]string) (json string, err error) {
	// sort keys
	keys := make([]string, len(plainmap))
	i := 0
	for k := range plainmap {
		keys[i] = k
		i++
	}
	sort.Strings(keys)
	// prepare json
	_, json, err = plainStringMapToFormattedJSON("", 0, keys, plainmap, "  ", "  ")
	if err != nil {
		return "", err
	}
	return "{" + json + "\n}", nil
}
386468
func (s String) List() []string {
	res := make(sortableSliceOfString, 0, len(s))
	for key := range s {
		res = append(res, key)
	}
	sort.Sort(res)
	return []string(res)
}
380360
func (v *Value) ObjxMapSlice(optionalDefault ...[](Map)) [](Map) {
	if s, ok := v.data.([]Map); ok {
		return s
	}

	if s, ok := v.data.([]map[string]interface{}); ok {
		result := make([]Map, len(s))
		for i := range s {
			result[i] = s[i]
		}
		return result
	}

	s, ok := v.data.([]interface{})
	if !ok {
		if len(optionalDefault) == 1 {
			return optionalDefault[0]
		}
		return nil
	}

	result := make([]Map, len(s))
	for i := range s {
		switch s[i].(type) {
		case Map:
			result[i] = s[i].(Map)
		case map[string]interface{}:
			result[i] = New(s[i])
		default:
			return nil
		}
	}
	return result
}
421907
func PrettyMap(m Map) string {
	var keys []string
	for k, _ := range m {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	var values []string
	for _, k := range keys {
		values = append(values, fmt.Sprintf("%q: %s", k, m[k]))
	}
	r := strings.Join(values, "\n")
	return fmt.Sprintf("%s", r)
}
692787
func (s *Set) Map(fn func(interface{}) interface{}) *Set {
	// Create a set to return with function applied
	mapSet := New()

	// Enumerate all elements and apply the function
	for _, e := range s.Enumerate() {
		// Apply the function, capture result
		mapSet.Add(fn(e))
	}

	return mapSet
}
206835
func sortedKeys(m interface{}) []string {
	v := reflect.ValueOf(m)
	keys := make([]string, v.Len())

	mapKeys := v.MapKeys()
	for i, k := range mapKeys {
		keys[i] = k.Interface().(string)
	}

	sort.Strings(keys)
	return keys
}
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  
}
944952
func Map(f, input interface{}) interface{} {
	inputValue := reflect.ValueOf(input)
	funcValue := reflect.ValueOf(f)
	_len := inputValue.Len()
	retValue := reflect.MakeSlice(reflect.TypeOf(input), _len, _len)
	for i := 0; i < _len; i++ {
		out := funcValue.Call([]reflect.Value{inputValue.Index(i)})
		retValue.Index(i).Set(out[0])
	}
	return retValue.Interface()
}
1057415
func (m *MultiMap) Get(key interface{}) (values []interface{}, found bool) {
	set, found := m.m[key]
	values = make([]interface{}, len(set))
	count := 0
	for value := range set {
		values[count] = value
		count++
	}
	return
}
349482
func CoalesceMap(data map[string]interface{}, fieldJoiner string) (map[string]interface{}, error) {
    return deepGetValues([]string{}, fieldJoiner, data), nil
}