restructure project
This commit is contained in:
22
internal/builtins/hash.go
Normal file
22
internal/builtins/hash.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package builtins
|
||||
|
||||
import (
|
||||
"monkey/internal/object"
|
||||
"monkey/internal/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")
|
||||
}
|
||||
Reference in New Issue
Block a user