daily pastebin goal
36%
SHARE
TWEET

[Perl 6] Set algebra.

cwchen Nov 8th, 2017 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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";
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top