1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-06-15 00:05:15 +02:00

31 lines
607 B
Go
Raw Normal View History

package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Returns the last element of an array.
* @param array (Array) - The target array.
* @returns (Read) - Last element of an array.
*/
func Last(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)
if err != nil {
return values.None, err
}
err = core.ValidateType(args[0], core.ArrayType)
if err != nil {
return values.None, nil
}
arr := args[0].(*values.Array)
return arr.Get(arr.Length() - 1), nil
}