Files
monkey/internal/builtins/abs.go
Chuck Smith fc6ceee02c
Some checks failed
Build / build (push) Failing after 5m21s
Publish Image / publish (push) Failing after 32s
Test / build (push) Failing after 5m8s
restructure project
2024-03-28 16:20:09 -04:00

25 lines
427 B
Go

package builtins
import (
"monkey/internal/object"
"monkey/internal/typing"
)
// Abs ...
func Abs(args ...object.Object) object.Object {
if err := typing.Check(
"abs", args,
typing.ExactArgs(1),
typing.WithTypes(object.INTEGER_OBJ),
); err != nil {
return newError(err.Error())
}
i := args[0].(*object.Integer)
value := i.Value
if value < 0 {
value = value * -1
}
return &object.Integer{Value: value}
}