Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement :exists and :delete for associative.
  • Loading branch information
jnthn committed Nov 7, 2012
1 parent 5dd878b commit 692a610
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/core/Any.pm
Expand Up @@ -219,6 +219,12 @@ my class Any {
multi method postcircumfix:<{ }>(\SELF: $key, :$BIND! is parcel) is rw {
SELF.bind_key($key, $BIND)
}
multi method postcircumfix:<{ }>(\SELF: $key, :$delete!) is rw {
SELF.delete($key)
}
multi method postcircumfix:<{ }>(\SELF: $key, :$exists!) is rw {
SELF.exists($key)
}
multi method postcircumfix:<{ }>(\SELF: Positional \key) is rw {
nqp::iscont(key)
?? SELF.at_key(key)
Expand All @@ -227,12 +233,28 @@ my class Any {
multi method postcircumfix:<{ }>(Positional $key, :$BIND!) is rw {
X::Bind::Slice.new(type => self.WHAT).throw
}
multi method postcircumfix:<{ }>(\SELF: Positional \key, :$delete!) is rw {
nqp::iscont(key)
?? SELF.at_key(key)
!! key.map({ SELF.delete($_) }).eager.Parcel
}
multi method postcircumfix:<{ }>(\SELF: Positional \key, :$exists!) is rw {
nqp::iscont(key)
?? SELF.at_key(key)
!! die("Cannot use exists adverb with a slice")
}
multi method postcircumfix:<{ }>(\SELF: Whatever) is rw {
SELF{SELF.keys}
}
multi method postcircumfix:<{ }>(Whatever, :$BIND!) is rw {
X::Bind::Slice.new(type => self.WHAT).throw
}
multi method postcircumfix:<{ }>(\SELF: Whatever, :$delete!) is rw {
SELF{SELF.keys}:delete
}
multi method postcircumfix:<{ }>(\SELF: Whatever, :$exists!) is rw {
SELF{SELF.keys}:delete
}

proto method at_key(|) { * }
multi method at_key(Any:D: $key) {
Expand Down

0 comments on commit 692a610

Please sign in to comment.