mirror of
https://github.com/42wim/matterbridge.git
synced 2024-12-20 16:02:01 -08:00
22 lines
473 B
Go
22 lines
473 B
Go
|
package objects
|
||
|
|
||
|
// append(arr, items...)
|
||
|
func builtinAppend(args ...Object) (Object, error) {
|
||
|
if len(args) < 2 {
|
||
|
return nil, ErrWrongNumArguments
|
||
|
}
|
||
|
|
||
|
switch arg := args[0].(type) {
|
||
|
case *Array:
|
||
|
return &Array{Value: append(arg.Value, args[1:]...)}, nil
|
||
|
case *ImmutableArray:
|
||
|
return &Array{Value: append(arg.Value, args[1:]...)}, nil
|
||
|
default:
|
||
|
return nil, ErrInvalidArgumentType{
|
||
|
Name: "first",
|
||
|
Expected: "array",
|
||
|
Found: arg.TypeName(),
|
||
|
}
|
||
|
}
|
||
|
}
|