The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::RandomCheck::ProbMonad - The probability monad

SYNOPSIS

  use Test::RandomCheck::ProbMonad;
  use Test::RandomCheck::PRNG;

  # A basic generator which returns random integers
  my $gen1 = gen {
      my ($r, $size) = @_;
      $r->next_int($size);
  };

  # It returns "******" strings randomly
  my $gen2 = $gen1->map(sub { '*' x $_[0] });

  # Build the new generator with the value from the original generator
  my $gen3 = $gen2->flat_map(sub{
      my $str = shift;
      gen {
          my ($r, $size) = @_;
          $str . $r->next_int($size);
      };
  });

  # Run generators
  my $r = Test::RandomCheck::PRNG->new;
  print $gen1->pick($r, 100), "\n"; # ex). 26
  print $gen2->pick($r, 100), "\n"; # ex). *****************
  print $gen3->pick($r, 100), "\n"; # ex). *********34

DESCRIPTION

Test::RandomCheck::Generator is a combinator to build random value generators used by Test::RandomCheck.

CONSTRUCTORS

<gen { ... };>

The most primitive constructor of this class. The block should return any values randomly. The block will be called on list context.

The block recieved $r and $size as its arguments. $r is an instance of Test::RandomCheck::RPNG.

METHODS

<my @random_values = $gen-pick($rand, $size);>>

Pick a set of values from this generator. You must pass an instance of Test::RandomCheck::RPNG.

<$gen-map(sub { ...; return @values });>>

A functor to apply normal functions to a Generator instance.

<$gen-flat_map(sub { ...; return $new_gen });>>

A kleisli composition to apply kleisli allows to a Generator instance.

SEE ALSO

Test::RandomCheck::Types

AUTHOR

Masahiro Honma <hiratara@cpan.org>

COPYRIGHT

Copyright 2013- Masahiro Honma

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO