Files
monkey/builtins/hash.go
Chuck Smith 6d234099d1
Some checks failed
Build / build (push) Successful in 11m16s
Test / build (push) Failing after 17m0s
type checking and error handling for builtins improved.
2024-03-25 16:18:08 -04:00

23 lines
434 B
Go

package builtins
import (
"monkey/object"
"monkey/typing"
)
// HashOf ...
func HashOf(args ...object.Object) object.Object {
if err := typing.Check(
"hash", args,
typing.ExactArgs(1),
); err != nil {
return newError(err.Error())
}
if hash, ok := args[0].(object.Hashable); ok {
return &object.Integer{Value: int64(hash.HashKey().Value)}
}
return newError("TypeError: hash() expected argument #1 to be hashable")
}