Perl6::Junction(3pm)
π Perl6::Junction π
okay bestie, so this is Perl6::Junction(3pm) β a page from the User Contributed Perl Documentation, and honestly? it's giving "tiny module, huge personality." sit with me for a sec and I'll tell you everything about it. no cap. π
β¨ NAME β¨
Perl6::Junction β Perl6 style Junction operators in Perl5. (yes, in Perl5. we're bringing the Perl6 vibes home. slay.) π¦
πΈ SYNOPSIS πΈ
use Perl6::Junction qw/ all any none one /;
if (any(@grant) eq 'su') {
...
}
if (all($foo, $bar) >= 10) {
...
}
if (qr/^\d+$/ == all(@answers)) {
...
}
if (all(@input) <= @limits) {
...
}
if (none(@pass) eq 'password') {
...
}
if (one(@answer) == 42) {
...
}
look at that. gorgeous. iconic. and every single one of those works, bestie. π
π DESCRIPTION π
so this is a lightweight module that hands you the 'Junction' operators β the ones you'll be reaching for most are any and all. main character energy fr fr.
it was inspired by the Perl6 design docs, over at <http://dev.perl.org/perl6/doc/design/exe/E06.html>. π§
it gives you a limited subset of what Quantum::Superpositions can do β go peek at the "SEE ALSO" section down below for the tea on that.
β οΈ okay this part is IMPORTANT, don't scroll past it: notice in the "SYNOPSIS" up there π that if you wanna match against a regular expression, you have to use==or!=. not=~and not!~. also you must use a regex object likeqr/\d/, and not a plain regex like/\d/. literally, this is the number one way people mess this up. π
π SUBROUTINES π
all()
returns an object that overloads these operators:
'<', '<=', '>', '>=', '==', '!=',
'lt', 'le', 'gt', 'ge', 'eq', 'ne',
and it returns true only if all arguments test true according to whichever operator you used. every single one. no stragglers. π
any()
returns an object that overloads these operators:
'<', '<=', '>', '>=', '==', '!=',
'lt', 'le', 'gt', 'ge', 'eq', 'ne',
and it returns true if any argument tests true according to the operator you used. just one is enough, bestie. π«Ά
none()
returns an object that overloads these operators:
'<', '<=', '>', '>=', '==', '!=',
'lt', 'le', 'gt', 'ge', 'eq', 'ne',
and it returns true only if no argument tests true according to the operator you used. zero. nada. not a single one. β¨
one()
returns an object that overloads these operators:
'<', '<=', '>', '>=', '==', '!=',
'lt', 'le', 'gt', 'ge', 'eq', 'ne',
and it returns true only if one and only one argument tests true according to the operator you used. exactly one. not two. not zero. one. π―
π¦ ALTERING JUNCTIONS π¦
here's the thing: you cannot alter junctions. like, at all. nope.
instead, you can create new junctions out of old junctions β do it by calling the values method on a junction. so:
my $numbers = any(qw/1 2 3 4 5/);
print $numbers == 3 ? 'Yes' : 'No'; # Yes
$numbers = any( grep { $_ != 3 } $numbers->values );
print $numbers == 3 ? 'Yes' : 'No'; # No
see how we rebuilt it? chef's kiss. π
π EXPORT π
'all', 'any', 'none', 'one' β as requested. you ask, you receive. π
every one of these subroutines can also be called by its fully qualified name, in case you don't want to export anything:
use Perl6::Junction;
if (Perl6::Junction::any( @questions )) {
...
}
π WARNING π
when you're comparing against a regular expression, you must remember to use a regular expression object: qr/\d/ β not /d/.
you must also use either == or !=. and the reason is lowkey annoying but very real: =~ and !~ cannot be overridden. that's it. that's the whole reason. π
β TO DO β
add overloading for arithmetic operators, so that this works:
$result = any(2,3,4) * 2;
if ($result == 8) {...}
(it doesn't yet, bestie. manifesting. π)
π₯ SUPPORT / BUGS π₯
submit to the CPAN bugtracker at <http://rt.cpan.org>. they're ready for you. π
π SEE ALSO π
Quantum::Superpositions gives you the same functionality as this module β and more. however, this module delivers its limited functionality at a much greater runtime speed, with benchmarks showing between 500% and 6000% improvement. not me doing the math twice, it really says 6000%. π₯
<http://dev.perl.org/perl6/doc/design/exe/E06.html> β "The Wonderful World of Junctions". go read it, it's iconic. π
πΈ AUTHOR πΈ
Carl Franks
π«Ά ACKNOWLEDGEMENTS π«Ά
thanks to "Curtis "Ovid" Poe" for the "ALTERING JUNCTIONS" changes in release 0.40000. we love a contributor moment. π
π COPYRIGHT AND LICENSE π
Copyright 2005, Carl Franks. All rights reserved.
this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself (perlgpl, perlartistic).
okay that's the whole page, bestie, you're officially a junction girlie now. go forth and any your way through life. πβ¨π¦
and that's a wrap on Perl6::Junction(3pm) from the User Contributed Perl Documentation, dated 2022-10-13, generated under perl v5.36.0. mwah. π
π¦ where this page comes from
- ubuntu noble: libperl6-junction-perl 1.60000-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libperl6-junction-perl 1.60000-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libperl6-junction-perl 1.60000-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms