Skip to content

Commit

Permalink
Add QuantHash.Setty|Baggy|Mixy coercer methods
Browse files Browse the repository at this point in the history
These are basically frontends for coercing to the given object, but
with maintaining the mutability of the object.  So:

  say (1,2,3).Set.Baggy;       # Bag(1, 2, 3)
  say (1,2,3).SetHash.Baggy;   # BagHash(1, 2, 3)
  • Loading branch information
lizmat committed Jul 31, 2018
1 parent 9b07e7b commit 3d9ea6e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/Bag.pm6
Expand Up @@ -43,6 +43,9 @@ my class Bag does Baggy {
X::Immutable.new(method => 'DELETE-KEY', typename => self.^name).throw;
}

method Setty(Bag:D:) { self.Set }
method Mixy(Bag:D:) { self.Mix }

#--- selection methods
multi method grabpairs(Bag:D: $count?) {
X::Immutable.new( method => 'grabpairs', typename => self.^name ).throw;
Expand Down
3 changes: 3 additions & 0 deletions src/core/BagHash.pm6
Expand Up @@ -66,6 +66,9 @@ my class BagHash does Baggy {
)
}

method Setty(BagHash:D:) { self.SetHash }
method Mixy(BagHash:D:) { self.MixHash }

#--- introspection methods
method total() { Rakudo::QuantHash.BAG-TOTAL($!elems) }

Expand Down
3 changes: 3 additions & 0 deletions src/core/Mix.pm6
Expand Up @@ -23,6 +23,9 @@ my class Mix does Mixy {
X::Immutable.new(method => 'DELETE-KEY', typename => self.^name).throw;
}

method Setty(Mix:D:) { self.Set }
method Baggy(Mix:D:) { self.Bag }

#--- introspection methods
multi method WHICH(Mix:D:) {
nqp::if(
Expand Down
3 changes: 3 additions & 0 deletions src/core/MixHash.pm6
Expand Up @@ -65,6 +65,9 @@ my class MixHash does Mixy {
)
}

method Setty(MixHash:D:) { self.SetHash }
method Baggy(MixHash:D:) { self.BagHash }

#--- object creation methods
multi method new(MixHash:_:) { nqp::create(self) }

Expand Down
3 changes: 3 additions & 0 deletions src/core/Set.pm6
Expand Up @@ -106,6 +106,9 @@ my class Set does Setty {
multi method DELETE-KEY(Set:D: \k) {
X::Immutable.new(method => 'DELETE-KEY', typename => self.^name).throw;
}

method Baggy(Set:D:) { self.Bag }
method Mixy(Set:D:) { self.Mix }
}

# vim: ft=perl6 expandtab sw=4
3 changes: 3 additions & 0 deletions src/core/SetHash.pm6
Expand Up @@ -226,6 +226,9 @@ my class SetHash does Setty {
)
)
}

method Baggy(SetHash:D:) { self.BagHash }
method Mixy(SetHash:D:) { self.MixHash }
}

# vim: ft=perl6 expandtab sw=4

0 comments on commit 3d9ea6e

Please sign in to comment.