Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hirokidaichi/p5-data-enumerator
data generator
https://github.com/hirokidaichi/p5-data-enumerator
Last synced: 7 days ago
JSON representation
data generator
- Host: GitHub
- URL: https://github.com/hirokidaichi/p5-data-enumerator
- Owner: hirokidaichi
- Created: 2011-11-14T12:54:36.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2011-11-17T13:48:15.000Z (about 13 years ago)
- Last Synced: 2024-04-20T19:51:50.741Z (7 months ago)
- Language: Perl
- Homepage:
- Size: 121 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
- Changelog: Changes
Awesome Lists containing this project
README
NAME
Data::Enumerator - some iterator utilities for perlSYNOPSIS
use Data::Enumerator qw/pattern generator/;my $cases = generator(
{ hoge => pattern(qw/a b c/),
fuga => pattern(qw/x y z/),
fixed => 0
}
);for my $case ( $cases->list ){
print pp($case);
}# { hoge => 'a',fuga => 'x'}
# { hoge => 'a',fuga => 'y'}
# { hoge => 'a',fuga => 'z'}
# { hoge => 'b',fuga => 'x'}
# { hoge => 'b',fuga => 'y'}
# { hoge => 'b',fuga => 'z'}
# { hoge => 'c',fuga => 'x'}
# { hoge => 'c',fuga => 'y'}
# { hoge => 'c',fuga => 'z'}DESCRIPTION
Data::Enumerator is utilities for iteration and test data generation
like itertools in python or C# IEnumerable.This module is marked EXPERIMENTAL. API could be changed without any
notice.pattern
to create an iterator by a provided list.my $gen = pattern(qw/a b c/);
# $gen->list => ('a','b','c')a generator can product another generator
my $gen = pattern(qw/a b c/)->product(pattern(qw/x y/));
# $gen->list
# ["a", "x"],
# ["a", "y"],
# ["b", "x"],
# ["b", "y"],
# ["c", "x"],
# ["c", "y"],generator
to create all pattern of data structure which contains pattern.my $users = generator({
sex => pattern(qw/male female/),
age => range(10,90,5),
category => pattern(qw/elf human dwarf gnome lizardman/)
})this code is a syntax sugar of the following code:
my $user = pattern(qw/male female/)
->product( range(10,90,5) )
->product( pattern(qw/elf human dwarf gnome lizardman/))
->select(sub{
+{ sex => $_[0]->[0],age => $_[0]->[1],category => $_[0]->[2]}
});so you can enumerate all pattern of users.
$user->each(sub{
my $user = shift;
$ do stuff
});AUTHOR
Daichi HirokiSEE ALSO
LICENSE
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.