diff --git a/src/core/Bag.pm b/src/core/Bag.pm index e7de21a69b1..ddf3fce4720 100644 --- a/src/core/Bag.pm +++ b/src/core/Bag.pm @@ -22,27 +22,7 @@ my class Bag does Baggy { ) } -#--- object creation methods - multi method new(Bag:_:) { - nqp::if( - nqp::eqaddr(self.WHAT,Bag), - bag(), - nqp::create(self) - ) - } - #--- interface methods - method SET-SELF(Bag:D: \elems) { - nqp::if( - nqp::elems(elems), - nqp::stmts( - nqp::bindattr(self,::?CLASS,'$!elems',elems), - self - ), - bag() - ) - } - multi method DELETE-KEY(Bag:D: \k) { X::Immutable.new(method => 'DELETE-KEY', typename => self.^name).throw; } diff --git a/src/core/BagHash.pm b/src/core/BagHash.pm index 2508549fba5..50cbd3063d3 100644 --- a/src/core/BagHash.pm +++ b/src/core/BagHash.pm @@ -55,9 +55,6 @@ my class BagHash does Baggy { ) } -#--- object creation methods - multi method new(BagHash:_:) { nqp::create(self) } - #--- introspection methods method total() { Rakudo::QuantHash.BAG-TOTAL($!elems) } diff --git a/src/core/Baggy.pm b/src/core/Baggy.pm index dc37bfed57d..51d0cd0af94 100644 --- a/src/core/Baggy.pm +++ b/src/core/Baggy.pm @@ -12,15 +12,6 @@ my role Baggy does QuantHash { # Immutables aspects of Bag/Mix, need to live to Bag/Mix respectively. #--- interface methods - method SET-SELF(Baggy:D: \elems) { - nqp::stmts( - nqp::if( - nqp::elems(elems), - nqp::bindattr(self,::?CLASS,'$!elems',elems) - ), - self - ) - } multi method ACCEPTS(Baggy:U: \other --> Bool:D) { other.^does(self) } diff --git a/src/core/Iterable.pm b/src/core/Iterable.pm index 198be53152f..3fd51431821 100644 --- a/src/core/Iterable.pm +++ b/src/core/Iterable.pm @@ -142,9 +142,15 @@ my role Iterable { nqp::if( (my $iterator := iterable.flat.iterator).is-lazy, Failure.new(X::Cannot::Lazy.new(:action,:what(type.^name))), - nqp::create(type).SET-SELF( - Rakudo::QuantHash.ADD-PAIRS-TO-MIX( + nqp::if( + nqp::elems(my $elems := Rakudo::QuantHash.ADD-PAIRS-TO-MIX( nqp::create(Rakudo::Internals::IterationSet),$iterator + )), + nqp::create(type).SET-SELF($elems), + nqp::if( + nqp::eqaddr(type,Mix), + mix(), + nqp::create(type) ) ) ) @@ -156,9 +162,15 @@ my role Iterable { nqp::if( (my $iterator := iterable.flat.iterator).is-lazy, Failure.new(X::Cannot::Lazy.new(:action,:what(type.^name))), - nqp::create(type).SET-SELF( - Rakudo::QuantHash.ADD-PAIRS-TO-BAG( + nqp::if( + nqp::elems(my $elems := Rakudo::QuantHash.ADD-PAIRS-TO-BAG( nqp::create(Rakudo::Internals::IterationSet),$iterator + )), + nqp::create(type).SET-SELF($elems), + nqp::if( + nqp::eqaddr(type,Bag), + bag(), + nqp::create(type) ) ) ) @@ -170,9 +182,15 @@ my role Iterable { nqp::if( (my $iterator := iterable.flat.iterator).is-lazy, Failure.new(X::Cannot::Lazy.new(:action,:what(type.^name))), - nqp::create(type).SET-SELF( - Rakudo::QuantHash.ADD-PAIRS-TO-SET( + nqp::if( + nqp::elems(my $elems := Rakudo::QuantHash.ADD-PAIRS-TO-SET( nqp::create(Rakudo::Internals::IterationSet),$iterator + )), + nqp::create(type).SET-SELF($elems), + nqp::if( + nqp::eqaddr(type,Set), + set(), + nqp::create(type) ) ) ) diff --git a/src/core/Mix.pm b/src/core/Mix.pm index 95b36f32550..b4762c40ef3 100644 --- a/src/core/Mix.pm +++ b/src/core/Mix.pm @@ -4,17 +4,6 @@ my class Mix does Mixy { has Real $!total-positive; #--- interface methods - method SET-SELF(Mix:D: \elems) { - nqp::if( - nqp::elems(elems), - nqp::stmts( - nqp::bindattr(self,::?CLASS,'$!elems',elems), - self - ), - mix() - ) - } - multi method DELETE-KEY(Mix:D: \k) { X::Immutable.new(method => 'DELETE-KEY', typename => self.^name).throw; } @@ -46,15 +35,6 @@ my class Mix does Mixy { ) } -#--- object creation methods - multi method new(Mix:_:) { - nqp::if( - nqp::eqaddr(self.WHAT,Mix), - mix(), - nqp::create(self) - ) - } - #--- selection methods multi method grab($count? --> Real:D) { X::Immutable.new( method => 'grab', typename => self.^name ).throw; diff --git a/src/core/QuantHash.pm b/src/core/QuantHash.pm index 4ce44add492..66574d54b22 100644 --- a/src/core/QuantHash.pm +++ b/src/core/QuantHash.pm @@ -1,4 +1,15 @@ my role QuantHash does Associative { + + method SET-SELF(QuantHash:D: \elems) { + nqp::stmts( + nqp::if( + nqp::elems(elems), + nqp::bindattr(self,::?CLASS,'$!elems',elems) + ), + self + ) + } + method Int ( --> Int:D) { self.total.Int } method Num ( --> Num:D) { self.total.Num } method Numeric ( --> Numeric:D) { self.total.Numeric } diff --git a/src/core/Set.pm b/src/core/Set.pm index 4bd6769ab85..f83552172a7 100644 --- a/src/core/Set.pm +++ b/src/core/Set.pm @@ -1,24 +1,6 @@ my class Set does Setty { has $!WHICH; - method SET-SELF(\elems) { - nqp::if( - nqp::elems(elems), - nqp::stmts( - nqp::bindattr(self,::?CLASS,'$!elems',elems), - self - ), - set() - ) - } - multi method new(Set:_:) { - nqp::if( - nqp::eqaddr(self.WHAT,Set), - set(), - nqp::create(self) - ) - } - multi method WHICH (Set:D:) { nqp::if( nqp::attrinited(self,Set,'$!WHICH'), diff --git a/src/core/SetHash.pm b/src/core/SetHash.pm index 2400d5a6f85..5d954512c0b 100644 --- a/src/core/SetHash.pm +++ b/src/core/SetHash.pm @@ -1,15 +1,5 @@ my class SetHash does Setty { - method SET-SELF(\elems) { - nqp::stmts( - nqp::if( - nqp::elems(elems), - nqp::bindattr(self,::?CLASS,'$!elems',elems) - ), - self - ) - } - #--- selector methods multi method grab(SetHash:D:) {