Advertisement
cwchen

[Perl 6] Set algebra.

Nov 8th, 2017
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.53 KB | None | 0 0
  1. my $a = (1, 2, 3).Set;
  2. my $b = (2, 4).Set;
  3.  
  4. # Union.
  5. $a (|) $b ~~ (1, 2, 3, 4).Set or die "Wrong status";
  6.  
  7. # Intersection.
  8. $a (&) $b ~~ (2).Set or die "Wrong status";
  9.  
  10. # Difference.
  11. $a (-) $b ~~ (1, 3).Set or die "Wrong status";
  12.  
  13. # Symmetric difference.
  14. $a (^) $b ~~ (1, 3, 4).Set or die "Wrong status";
  15.  
  16. my $c = (2, 3).Set;
  17.  
  18. # Superset.
  19. $a (>=) $c or die "Wrong status";
  20.  
  21. # Strict superset.
  22. $a (>) $c or die "Wrong status";
  23.  
  24. # Subset.
  25. $c (<) $a or die "Wrong status";
  26.  
  27. # Strict subset.
  28. $c (<=) $a or die "Wrong status";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement