func newFn(f reflect.Value) (Fn, error) {
	if f.Kind() != reflect.Func {
		return Fn{}, fmt.Errorf("expected function")
	}
	tp := f.Type()
	if in := tp.NumIn(); in != 2 {
		return Fn{}, fmt.Errorf("expected function with 2 arguments, got: %d", in)
	}
	t1, err := reflectutil.New(tp.In(0))
	if err != nil {
		return Fn{}, err
	}
	t2, err := reflectutil.New(tp.In(1))
	if err != nil {
		return Fn{}, err
	}
	if t1.Type != t2.Type {
		return Fn{}, fmt.Errorf("expected same types, got: %v, %v", t1, t2)
	}
	if out := tp.NumOut(); out != 1 {
		return Fn{}, fmt.Errorf("expected function with a single return value, got: %d", out)
	}
	if out := tp.Out(0); out.Kind() != reflect.Int {
		return Fn{}, fmt.Errorf("expected function with int return value, got: %v", out)
	}
	return Fn{
		fn: func(lhs, rhs reflect.Value) int {
			return f.Call([]reflect.Value{t1.Convert(lhs), t2.Convert(rhs)})[0].Interface().(int)
		},
		t: t1,
	}, nil
}
newFn converts a given function value to the a compare function. It also checks that the
function `f` is of the right form (func(T, T) int) and that T is of the given type t. If the
given type t is nil, it will be set to the type of the first argument of f.
package order
import (
	"fmt"
	"reflect"
	"github.com/posener/order/internal/reflectutil"
)
type Fns []Fn
type Fn struct {
	fn func(lhs, rhs reflect.Value) int
	t reflectutil.T
}