3 ms·
In Perl 6, we can do much the same without all of the boilerplate. class a {}; multi sub infix:<==> (a $a, $b) { True } if a == 1 && a
by labster 9y ago
In Perl 6, we can do much the same without all of the boilerplate.
class a {};
multi sub infix:<==> (a $a, $b) {
True
}
if a == 1 && a == 2 && a == 3 {
say "true!"
}
If you wanted to make an actual iterator out of `a`, you could do:
multi sub infix:<==> (a $a, $b) {
++(state $) == $b
}
In that case, `a` would equal 1, 2, and 3 in that order. 5 is right out.
- perlgeek 9y agoOr you could just use a junction: my \a = any(1, 2, 3); if ( a == 1 && a == 2 && a == 3 ) { say "OMG quantum superposition!!!"; } For those wondering what's going on: https://docs.perl6.org/type/Junction.html https://docs.perl6.org/type/Junction.html :-)