Hacker News new | comments | show | ask | jobs | submit login

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.



Or 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 :-)




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: