List::...ctions(3pm)

πŸ“¦
version 2.028003 Β· 4 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’… List::...ctions(3pm) β€” List::Objects::WithUtils::Role::Array::WithJunctions

okay bestie, so this is a User Contributed Perl Documentation page, and the module in question is List::Objects::WithUtils::Role::Array::WithJunctions. the whole vibe? junctions, but for your arrays. ✨


🌸 NAME 🌸

List::Objects::WithUtils::Role::Array::WithJunctions β€” Add junctions πŸŽ€

like, it literally just adds junctions. that's the whole thing. iconic behaviour honestly.


✨ SYNOPSIS ✨

## Via List::Objects::WithUtils::Array ->
use List::Objects::WithUtils 'array';

my $array = array(qw/ a b c /);

if ( $array->any_items eq 'b' ) {
  ...
}

if ( $array->all_items eq 'a' ) {
  ...
}

if ( $array->any_items == qr/^b/ ) {
  ...
}

## As a Role ->
use Role::Tiny::With;
with 'List::Objects::WithUtils::Role::Array',
     'List::Objects::WithUtils::Role::Array::WithJunctions';

see how she just glides in? two ways to do it β€” either you grab it through List::Objects::WithUtils::Array, or you compose it in yourself as a Role with Role::Tiny::With. both slay. 🫢


πŸ’– DESCRIPTION πŸ’–

so these methods hand you overloaded List::Objects::WithUtils::Array::Junction objects, and you can compare them against values using normal Perl comparison operators. no fancy footwork required, bestie. πŸ’…

Regular expressions? yes ma'am. you match them by handing a qr// regular expression object to the == or != operators. πŸ”₯

no support for the ~~ experimental smart-match operator. not a thing here, don't ask, she said no. πŸ’€

and here's the fun part β€” the junction objects you get back are subclasses of List::Objects::WithUtils::Array, which means you can manipulate junctions (of varying degrees of sanity, and I'm quoting the docs there, ngl that's a whole mood 😭). a simple case might be generating a new junction out of an old junction:

my $list = array(3, 4, 5);
if ( (my $anyof = $list->any_items) > 2 ) {
  my $incr = $anyof->map(sub { $_[0] + 1 })->all_items;
  if ( $incr > 6 ) {
    # ...
  }
  # Drop junction magic again:
  my $plain = array( $incr->all );
}

not me reading that and going "okay main character energy" 🧚


πŸ‘‘ any_items

Returns the overloaded any object for the current array; a comparison is true if any items in the array satisfy the condition. it's giving "at least one of y'all". ⭐


πŸ¦‹ all_items

Returns the overloaded all object for the current array; a comparison is true only if all items in the array satisfy the condition. strict queen. everybody has to show up for this one. πŸ‘‘


🌈 AUTHOR 🌈

Jon Portnoy <avenj@cobaltirc.org>


and that's a wrap, bestie πŸ’œ this was List::...ctions(3pm), part of the User Contributed Perl Documentation, running on perl v5.38.2 and dated 2024-03-07 β€” go forth and junction responsibly, no cap. πŸ“βœ¨

πŸ“¦ where this page comes from