github.com/searKing/golang/go@v1.2.74/container/slice/string.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package slice
     6  
     7  import "reflect"
     8  
     9  func normalizeSlice(s []interface{}, as interface{}) interface{} {
    10  	kind := reflect.ValueOf(as).Kind()
    11  	switch kind {
    12  	case reflect.Map:
    13  		return normalizeSliceAsMap(s)
    14  	}
    15  	return s
    16  }
    17  func normalizeElem(elem, as interface{}) interface{} {
    18  	return elem
    19  }
    20  
    21  func normalizeSliceAsMap(s []interface{}) interface{} {
    22  	bs := make(map[interface{}]interface{})
    23  	for _, m := range s {
    24  		pair := m.(MapPair)
    25  		bs[pair.Key] = pair.Value
    26  	}
    27  	return bs
    28  }