cwchen icon

[Perl 6] Set algebra.

cwchen | PRO | 11/09/17 02:27:52 AM UTC | 0 ⭐ | 8378 👁️ | Never ⏰ | []
Perl 6 |

0 B

|

None

|

0 👍

/

0 👎

my $a = (1, 2, 3).Set;
my $b = (2, 4).Set;
 
# Union.
$a (|) $b ~~ (1, 2, 3, 4).Set or die "Wrong status";
 
# Intersection.
$a (&) $b ~~ (2).Set or die "Wrong status";
 
# Difference.
$a (-) $b ~~ (1, 3).Set or die "Wrong status";
 
# Symmetric difference.
$a (^) $b ~~ (1, 3, 4).Set or die "Wrong status";
 
my $c = (2, 3).Set;
 
# Superset.
$a (>=) $c or die "Wrong status";
 
# Strict superset.
$a (>) $c or die "Wrong status";
 
# Subset.
$c (<) $a or die "Wrong status";
 
# Strict subset.
$c (<=) $a or die "Wrong status";

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎