Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added KindsOf method to Value type #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 20 additions & 3 deletions kind.go
Expand Up @@ -121,6 +121,17 @@ func (k Kind) String() string {

func (k Kind) mask() kindMask { return kindMask(1 << k) }

// KindList List of Kinds pretty self explanitory
type KindList []Kind

func (kinds KindList) String() string {
var res []string
for _, kind := range kinds {
res = append(res, kind.String())
}
return strings.Join(res, ",")
}

type kindMask uint64

// if kNumKinds > 64, then this will fail at compile time.
Expand All @@ -131,15 +142,21 @@ func (mask kindMask) Is(k Kind) bool {
}

func (mask kindMask) String() string {
var res []string
kinds := mask.Kinds()
return kinds.String()
}

func (mask kindMask) Kinds() KindList {
var kinds KindList
for k := Kind(0); k < kNumKinds; k++ {
if mask.Is(k) {
res = append(res, k.String())
kinds = append(kinds, k)
}
}
return strings.Join(res, ",")
return kinds
}


func mask(kinds ...Kind) kindMask {
var res kindMask
for _, k := range kinds {
Expand Down
6 changes: 6 additions & 0 deletions v8.go
Expand Up @@ -449,6 +449,12 @@ func (v *Value) IsKind(k Kind) bool {
return v.kindMask.Is(k)
}

// KindsOf will get a list of Kinds for the underlying value.
// The kind of a value is set when the value is created and will not change.
func (v *Value) KindsOf() KindList {
return v.kindMask.Kinds()
}

// New creates a new instance of an object using this value as its constructor.
// If this value is not a function, this will fail.
func (v *Value) New(args ...*Value) (*Value, error) {
Expand Down