Perl6::Junction(3pm)

πŸ“¦
version 1.60000 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 like qr/\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 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