seperated builtins
This commit is contained in:
21
object/builtin_last.go
Normal file
21
object/builtin_last.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package object
|
||||
|
||||
// Last ...
|
||||
func Last(args ...Object) Object {
|
||||
if len(args) != 1 {
|
||||
return newError("wrong number of arguments. got=%d, want=1",
|
||||
len(args))
|
||||
}
|
||||
if args[0].Type() != ARRAY_OBJ {
|
||||
return newError("argument to `last` must be ARRAY, got %s",
|
||||
args[0].Type())
|
||||
}
|
||||
|
||||
arr := args[0].(*Array)
|
||||
length := len(arr.Elements)
|
||||
if length > 0 {
|
||||
return arr.Elements[length-1]
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user