File: 10reduce.t

package info (click to toggle)
liblist-keywords-perl 0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 200 kB
  • sloc: perl: 467; makefile: 3
file content (23 lines) | stat: -rw-r--r-- 503 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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

use List::Keywords 'reduce';

# Short cornercases
{
   is( ( reduce { die "ARGH" } () ), undef, 'reduce on empty list yields undef' );

   is( ( reduce { die "ARGH" } 123 ), 123, 'reduce on singleton list yields value directly' );
}

# basic sum
is( ( reduce { $a + $b } 1 .. 5 ), 15, 'sum of 1..5 is 15' );

# reduce is definitely a left-fold
is( ( reduce { "($a+$b)" } "a" .. "d" ), "(((a+b)+c)+d)", 'reduce is a left-fold' );

done_testing;