List::Objects::WithUtils::Role::Array::WithJunctions(3pm)

List::Objects::WithUtils::Role::Array::WithJunctions3pm

Add junctions

Usage

  ## 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';

Overview

These methods supply overloaded List::Objects::WithUtils::Array::Junction objects that can be compared with values using normal Perl comparison operators.

Regular expressions can be matched by providing a "qr//" regular expression object to the "==" or "!=" operators.

There is no support for the "~~" experimental smart-match operator.

The junction objects returned are subclasses of List::Objects::WithUtils::Array, allowing manipulation of junctions (of varying degrees of sanity) -- 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 );
  }

any_items

Returns the overloaded any object for the current array; a comparison is true if any items in the array satisfy the condition.

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.

Releases

4 releases since Debian 10 (Buster); the text changed 3 times.

  1. 10
  2. 11
  3. 12
  4. 13

Author

Jon Portnoy <[email protected]>

From liblist-objects-withutils-perl 2.028003-5 in Debian 13 (Trixie). Parsed by carta from the page's man source.