Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #158 from lizmat/deleteadverbkvpkv

Support for subscript adverb :delete in combination with :kv :p :k :v
  • Loading branch information...
commit 12b13e5254a366dd6e3950d26c7a0abb24b5f929 2 parents 9cf3a88 + d292900
lizmat lizmat authored
Showing with 75 additions and 14 deletions.
  1. +75 −14 src/core/Any.pm
89 src/core/Any.pm
View
@@ -329,10 +329,30 @@ my class Any {
multi method postcircumfix:<{ }>(\SELF: $key, Mu :$BIND! is parcel) is rw {
SELF.bind_key($key, $BIND)
}
- multi method postcircumfix:<{ }>(\SELF: $key, :$delete! where so $delete) is rw {
- SELF.delete($key)
- }
- multi method postcircumfix:<{ }>(\SELF: $key, :$exists!) is rw {
+ multi method postcircumfix:<{ }>(
+ \SELF: $key,
+ :$delete! where so $delete,
+ :$kv = $default, :$p = $default, :$k = $default, :$v = $default
+ ) is rw {
+ $p & $k & $kv & $v === $default # :delete only
+ ?? SELF.delete($key) !!
+ $kv !=== $default
+ ?? ( !$kv | SELF.exists($key)
+ ?? ( $key, SELF.delete($key) )
+ !! () ) !!
+ $p !=== $default
+ ?? ( !$p | SELF.exists($key)
+ ?? RWPAIR($key, SELF.delete($key))
+ !! () ) !!
+ $k !=== $default
+ ?? ( !$k | SELF.exists($key)
+ ?? ( SELF.delete($key); $key )
+ !! () ) !!
+ !$v | SELF.exists($key)
+ ?? SELF.delete($key)
+ !! ();
+ }
+ multi method postcircumfix:<{ }>(\SELF: $key, :$exists! ) is rw {
!( SELF.exists($key) ?^ $exists )
}
multi method postcircumfix:<{ }>(\SELF: $key, :$p!) is rw {
@@ -355,10 +375,47 @@ my class Any {
X::Bind::Slice.new(type => self.WHAT).throw
}
multi method postcircumfix:<{ }>(
- \SELF: Positional \key, :$delete! where so $delete ) is rw {
- nqp::iscont(key)
- ?? SELF.delete(key)
- !! key.map({ SELF.delete($_) }).eager.Parcel
+ \SELF: Positional \key,
+ :$delete! where so $delete,
+ :$kv = $default, :$p = $default, :$k = $default, :$v = $default
+ ) is rw {
+
+ # handle single key immediately
+ return SELF{key}:$delete:$kv:$p:$k:$v if nqp::iscont(key);
+
+ $kv & $p & $k & $v === $default # :delete only
+ ?? key.map({ SELF.delete($_) }).eager.Parcel !!
+ $kv !=== $default
+ ?? ( $kv
+ ?? key.map( {
+ SELF.exists($_) ?? ( $_, SELF.delete($_) ) !! ()
+ } ).eager.Parcel
+ !! key.map( {
+ ( $_, SELF.delete($_) )
+ } ).eager.Parcel ) !!
+ $p !=== $default
+ ?? ( $p
+ ?? key.map( {
+ SELF.exists($_) ?? RWPAIR($_, SELF.delete($_)) !! ()
+ } ).eager.Parcel
+ !! key.map( {
+ RWPAIR($_, SELF.delete($_))
+ } ).eager.Parcel ) !!
+ $k !=== $default
+ ?? ( $k
+ ?? key.map( {
+ SELF.exists($_) ?? ( SELF.delete($_); $_ ) !! ()
+ } ).eager.Parcel
+ !! key.map( {
+ SELF.delete($_); $_
+ } ).eager.Parcel ) !!
+ $v
+ ?? key.map( {
+ SELF.exists($_) ?? SELF.delete($_) !! ()
+ } ).eager.Parcel
+ !! key.map( {
+ SELF.delete($_)
+ } ).eager.Parcel;
}
multi method postcircumfix:<{ }>(
\SELF: Positional \key, :$exists!) is rw {
@@ -394,23 +451,27 @@ my class Any {
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,
+ :$delete! where so $delete,
+ :$kv = $default, :$p = $default, :$k = $default, :$v = $default
+ ) is rw {
+ SELF{SELF.keys}:$delete:$kv:$p:$k:$v;
}
multi method postcircumfix:<{ }>(\SELF: Whatever, :$exists!) is rw {
SELF{SELF.keys}:$exists
}
multi method postcircumfix:<{ }>(\SELF: Whatever, :$p!) is rw {
- SELF{SELF.keys}:p
+ SELF{SELF.keys}:$p
}
multi method postcircumfix:<{ }>(\SELF: Whatever, :$kv!) is rw {
- SELF{SELF.keys}:kv
+ SELF{SELF.keys}:$kv
}
multi method postcircumfix:<{ }>(\SELF: Whatever, :$k!) is rw {
- SELF{SELF.keys}:k
+ SELF{SELF.keys}:$k
}
multi method postcircumfix:<{ }>(\SELF: Whatever, :$v!) is rw {
- SELF{SELF.keys}:v
+ SELF{SELF.keys}:$v
}
proto method at_key(|) { * }
Please sign in to comment.
Something went wrong with that request. Please try again.