Comparer returns an [Option] that determines whether two values are equal to each other. The comparer f must be a function "func(T, T) bool" and is implicitly filtered to input values assignable to T. If T is an interface, it is possible that f is called with two values of different concrete types
(f interface{})
| 353 | // - Deterministic: equal(x, y) == equal(x, y) |
| 354 | // - Pure: equal(x, y) does not modify x or y |
| 355 | func Comparer(f interface{}) Option { |
| 356 | v := reflect.ValueOf(f) |
| 357 | if !function.IsType(v.Type(), function.Equal) || v.IsNil() { |
| 358 | panic(fmt.Sprintf("invalid comparer function: %T", f)) |
| 359 | } |
| 360 | cm := &comparer{fnc: v} |
| 361 | if ti := v.Type().In(0); ti.Kind() != reflect.Interface || ti.NumMethod() > 0 { |
| 362 | cm.typ = ti |
| 363 | } |
| 364 | return cm |
| 365 | } |
| 366 | |
| 367 | type comparer struct { |
| 368 | core |