Files
monkey/internal/builtins/hash.go
Chuck Smith 4c9ec5aaaa
Some checks failed
Build / build (push) Failing after 6m4s
Test / build (push) Failing after 6m33s
server
2024-04-02 12:21:41 -04:00

24 lines
494 B
Go

package builtins
import (
"monkey/internal/context"
"monkey/internal/object"
"monkey/internal/typing"
)
// HashOf ...
func HashOf(ctx context.Context, 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.Hasher); ok {
return object.Integer{Value: int64(hash.Hash().Value)}
}
return newError("TypeError: hash() expected argument #1 to be hashable")
}