Example #1
0
func ExampleMakeGetKeys() {
	// let's extract the keys of a map
	var getKeys func(map[string]int) []string
	if err := funcs.MakeGetKeys(&getKeys); err != nil {
		log.Fatal(err)
	}
	Map := map[string]int{"a": 1, "b": 2, "c": 3, "d": 4}
	keys := getKeys(Map)
	fmt.Println(len(keys))
	// Output:
	// 4
}
Example #2
0
	result += "fields :[\n"
	for i, field := range meta.fields {
		if i > 0 {
			result += ",\n "
		}
		result += "{" + field.String() + "}"
	}
	return result + "\n]}\n"
}

var (
	keyValuesByObjectID func(collection []reflect.Value, selector func(reflect.Value) bson.ObjectId) map[bson.ObjectId]reflect.Value
	_                   = funcs.Must(funcs.MakeKeyBy(&keyValuesByObjectID))

	getKeys func(map[bson.ObjectId]reflect.Value) []bson.ObjectId
	_       = funcs.Must(funcs.MakeGetKeys(&getKeys))

	flatten func([][]interface{}) []interface{}
	_       = funcs.Must(funcs.MakeFlatten(&flatten))

	mapResultsToInterfaces func([]map[string]interface{}, func(map[string]interface{}) []interface{}) [][]interface{}
	_                      = funcs.Must(funcs.MakeMap(&mapResultsToInterfaces))

	keyResultsBySourceID func(results []map[string]interface{}, mapper func(result map[string]interface{}) (id bson.ObjectId)) map[bson.ObjectId]map[string]interface{}
	_                    = funcs.Must(funcs.MakeKeyBy(&keyResultsBySourceID))

	mapResultsToRelatedObjectIds func(results []map[string]interface{}, mapper func(result map[string]interface{}) bson.ObjectId) []bson.ObjectId
	_                            = funcs.Must(funcs.MakeMap(&mapResultsToRelatedObjectIds))

	keyRelatedResultsByObjectID func(results []reflect.Value, mapper func(result reflect.Value) bson.ObjectId) map[bson.ObjectId]reflect.Value
	_                           = funcs.Must(funcs.MakeKeyBy(&keyRelatedResultsByObjectID))