File: 10_fold.t

package info (click to toggle)
libperlude-perl 0.61-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 360 kB
  • sloc: perl: 903; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 629 bytes parent folder | download
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
29
30
31
32
33
34
35
36
37
38
39
#! /usr/bin/perl
use strict;
use warnings;
use Test::More;
use Perlude::Lazy;

my @tests =
( []
, [undef] 
, [1..10] 
, ['']
, ["haha"]
);

plan tests => 3*@tests;

for my $t (@tests) {
    is_deeply
    ( [fold unfold @$t]
    , $t
    , "fold unfold => id"
    )
}

# fold in void context
for my $t (@tests) {
    my @l = @$t;
    my $n = 1+@l;
    #fold apply { $n--; @_ } unfold @$t;
    fold enlist sub { $n--; @l ? (shift @l) : () };
    is $n, 0, (0+@$t)." elements in void context";
}

# fold in scalar context
for my $t (@tests) {
    my $n = fold unfold @$t;
    is $n, 0+@$t, (0+@$t)." elements in scalar context";
}