Last active
August 29, 2015 14:08
-
-
Save ab5tract/7b8d2a82a2674f4d41be to your computer and use it in GitHub Desktop.
Two possible approaches to coercion in set comparisons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| multi sub infix:<<(<)>>(Bag $a, Bag $b --> Bool) { | |
| [&&] $a.keys.map({ $a{$_} < $b{$_} }); | |
| } | |
| multi sub infix:<<(<)>>(Bag $a, Any $b --> Bool) { | |
| $b = $b.bag(:view); | |
| [&&] $a.keys.map({ $a{$_} < $b{$_} }); | |
| } | |
| multi sub infix:<<(<)>>(Any $a, Bag $b --> Bool) { | |
| $a = $a.bag(:view); | |
| [&&] $a.keys.map({ $a{$_} < $b{$_} }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| only sub infix:<<(<=)>>(Any $a, Any $b --> Bool) { | |
| my ($c,$d); | |
| given $a|$b { | |
| when Mix { $c = $a.Mix(:view); $d = $b.Mix(:view); } | |
| when Bag { $c = $a.Bag(:view); $d = $b.Bag(:view); } | |
| default { $c = $a.Set(:view); $d = $b.Set(:view); } | |
| } | |
| [&&] $c.keys.map({ $c{$_} <= $d{$_} }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment