示例#1
0
func TestMakeIndexOfErrors(t *testing.T) {
	var IndexOfInts func([]int, int) int
	err := funcs.MakeIndexOf(IndexOfInts)
	test.Fatal(t, err, funcs.ErrNotAPointer)
	err = funcs.MakeIndexOf(&struct{}{})
	test.Fatal(t, err, funcs.ErrNotAFunction)
	var IndexOfString func([]string, int) int
	err = funcs.MakeIndexOf(&IndexOfString)
	test.Fatal(t, err, funcs.ErrUnexpectedType)
	var IndexOfByte func([]byte, byte) string
	err = funcs.MakeIndexOf(&IndexOfByte)
	test.Fatal(t, err, funcs.ErrUnexpectedType)
	var IndexOfArray func([][]string, []string) int
	err = funcs.MakeIndexOf(&IndexOfArray)
	test.Fatal(t, err, funcs.ErrNoComparableType)
}
示例#2
0
func ExampleMakeIndexOf() {
	// Let's make an indexOf function
	var IndexOfInts func([]int, int) int
	fmt.Println(funcs.MakeIndexOf(&IndexOfInts))
	fmt.Println(IndexOfInts([]int{1, 2, 4}, 2))
	fmt.Println(IndexOfInts([]int{2, 6, 8}, 1))

	// Output:
	// <nil>
	// 1
	// -1
}
示例#3
0
	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))

	mapInterfacesToObjectIds func([]interface{}, func(interface{}) bson.ObjectId) []bson.ObjectId
	_                        = funcs.Must(funcs.MakeMap(&mapInterfacesToObjectIds))

	filter func([]bson.ObjectId, func(id bson.ObjectId) bool) []bson.ObjectId
	_      = funcs.Must(funcs.MakeFilter(&filter))

	indexOf func([]interface{}, interface{}) int
	_       = funcs.Must(funcs.MakeIndexOf(&indexOf))

	indexOfString func([]string, string) int
	_             = funcs.Must(funcs.MakeIndexOf(&indexOfString))
)