NAME

MCE::Shared::Sequence - Sequence helper class

VERSION

This document describes MCE::Shared::Sequence version 1.699_010

SYNOPSIS

# non-shared
use MCE::Shared::Sequence;

my $seq = MCE::Shared::Sequence->new( $begin, $end, $step, $fmt );

# shared
use MCE::Hobo;
use MCE::Shared Sereal => 1;

my $seq = MCE::Shared->sequence( 1, 100 );

sub parallel {
   my ( $id ) = @_;
   while ( my $num = $seq->next ) {
      print "$id: $num\n";
   }
}

MCE::Hobo->new( \&parallel, $_ ) for 1 .. 8;

$_->join for MCE::Hobo->list();

DESCRIPTION

A number sequence class for MCE::Shared.

API DOCUMENTATION

new ( begin, end [, step, format ] )

Constructs a new object. step, if omitted, defaults to 1 if begin is smaller than end or -1 if begin is greater than end. The format string is passed to sprintf behind the scene (% may be omitted).

$seq_n_formatted = sprintf( "%4.1f", $seq_n );

Options may be specified later with rewind before calling next.

# non-shared
use MCE::Shared::Sequence;

$seq = MCE::Shared::Sequence->new( -1, 1, 0.1, "%4.1f" );
$seq = MCE::Shared::Sequence->new( );
$seq->rewind( -1, 1, 0.1, "%4.1f" );

# shared
use MCE::Shared;

$seq = MCE::Shared->sequence( 1, 100 );
$seq = MCE::Shared->sequence( );
$seq->rewind( 1, 100 );
next

Returns the next computed sequence. An undefined value is returned when the computed value exceeds the value held by end.

$num = $seq->next;
rewind ( begin, end [, step, format ] )

When options are specified, resets parameters internally. Otherwise, sets the initial value back to the value held by begin.

$seq->rewind( 10, 1, -1 );
$seq->next; # repeatedly

$seq->rewind;
$seq->next; # repeatedly

INDEX

MCE, MCE::Core, MCE::Shared

AUTHOR

Mario E. Roy, <marioeroy AT gmail DOT com>