github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/arrays/sorted.go (about) 1 package arrays 2 3 import ( 4 "context" 5 6 "github.com/MontFerret/ferret/pkg/runtime/core" 7 "github.com/MontFerret/ferret/pkg/runtime/values" 8 "github.com/MontFerret/ferret/pkg/runtime/values/types" 9 ) 10 11 // SORTED sorts all elements in anyArray. 12 // The function will use the default comparison order for FQL value types. 13 // @param {Any[]} array - Target array. 14 // @return {Any[]} - Sorted array. 15 func Sorted(_ context.Context, args ...core.Value) (core.Value, error) { 16 err := core.ValidateArgs(args, 1, 1) 17 18 if err != nil { 19 return values.None, err 20 } 21 22 err = core.ValidateType(args[0], types.Array) 23 24 if err != nil { 25 return values.None, err 26 } 27 28 arr := args[0].(*values.Array) 29 30 if arr.Length() == 0 { 31 return values.NewArray(0), nil 32 } 33 34 return arr.Sort(), nil 35 }