mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-06-24 09:41:00 +00:00
feat: add which_max and which_min to retrieve extreme element indices
Implement reflection-based WhichMax and WhichMin to dynamically find the index or key of the maximum/minimum element in slices, arrays, or maps. Functions validate orderability, handle empty collections, and dispatch via reflect.Kind. Expose as which_max and which_min GVal functions, with float64 type assertions for compatibility and preserved error handling.
This commit is contained in:
@@ -141,6 +141,20 @@ var OBILang = gval.NewLanguage(
|
||||
gval.Function("max", func(args ...interface{}) (interface{}, error) {
|
||||
return obiutils.Max(args[0])
|
||||
}),
|
||||
gval.Function("which_max", func(args ...interface{}) (interface{}, error) {
|
||||
result, err := obiutils.WhichMax(args[0])
|
||||
if idx, ok := result.(int); ok {
|
||||
return float64(idx), nil
|
||||
}
|
||||
return result, err
|
||||
}),
|
||||
gval.Function("which_min", func(args ...interface{}) (interface{}, error) {
|
||||
result, err := obiutils.WhichMin(args[0])
|
||||
if idx, ok := result.(int); ok {
|
||||
return float64(idx), nil
|
||||
}
|
||||
return result, err
|
||||
}),
|
||||
|
||||
gval.Function("filtermin", func(args ...interface{}) (interface{}, error) {
|
||||
return obiutils.FilterMin(args[0], args[1])
|
||||
|
||||
Reference in New Issue
Block a user