File: 30_oo.t

package info (click to toggle)
libiterator-simple-perl 0.07-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 180 kB
  • sloc: perl: 1,116; makefile: 2
file content (28 lines) | stat: -rwxr-xr-x 685 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use Test::More tests => 3;

use strict;
use warnings;

use Iterator::Simple qw(iter list);

my $itr;
{
	$itr = iter(['foo','bar'])->enumerate;
	$itr = iter([1,$itr ,3,4]);
	$itr = $itr->flatten();
	$itr = $itr->chain(iter ['dog','cat']);
	is_deeply list($itr) => [1,[0,'foo'],[1,'bar'],3,4,'dog','cat'], 'misc filter method';
}

{
	my $trans1 = sub { $_ ** 2 };
	my $trans2 = sub { ":$_"  };

	$itr = iter([1,2,3,4,5]);
	$itr = $itr->filter($trans1)->filter($trans2);
	is_deeply list($itr) => [':1', ':4', ':9', ':16', ':25'], 'general filter';

	$itr = iter([1,2,3,4,5]);
	$itr = $itr | $trans1 | $trans2;
	is_deeply list($itr) => [':1', ':4', ':9', ':16', ':25'], 'pipe overload';
}