line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package fp::functionals; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
4636
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
51
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# use fp's import routine |
10
|
1
|
|
|
1
|
|
5
|
use fp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN { |
13
|
1
|
|
|
1
|
|
441
|
*import = \&fp::import; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# right and left currying routines |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub curry ($@) { |
21
|
9
|
|
|
9
|
1
|
15
|
my ($f, @args) = @_; |
22
|
9
|
|
|
17
|
|
44
|
sub { $f->(@args, @_) }} |
|
17
|
|
|
|
|
37
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub rcurry ($@) { |
25
|
1
|
|
|
1
|
1
|
4
|
my ($f, @args) = @_; |
26
|
1
|
|
|
1
|
|
7
|
sub { $f->(@_, @args) }} |
|
1
|
|
|
|
|
6
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
## ---------------------------------------------- |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# composition functions to compose |
31
|
|
|
|
|
|
|
# functions out of other functions |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub simple_compose ($$) { |
34
|
1
|
|
|
1
|
1
|
2
|
my ($f, $f2) = @_; |
35
|
1
|
|
|
1
|
|
6
|
sub { $f2->($f->(@_)) }} |
|
1
|
|
|
|
|
4
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub compose (@); # pre-declare sub so it can be used in recursion |
38
|
|
|
|
|
|
|
sub compose (@) { |
39
|
5
|
|
|
5
|
1
|
9
|
my ($f, $f2, @rest) = @_; |
40
|
|
|
|
|
|
|
(!$f2) ? |
41
|
|
|
|
|
|
|
$f |
42
|
|
|
|
|
|
|
: |
43
|
5
|
100
|
|
4
|
|
35
|
compose sub { $f2->($f->(@_)) }, @rest } |
|
4
|
|
|
|
|
7
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
## ---------------------------------------------- |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# identity function |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub always ($) { |
50
|
1
|
|
|
1
|
1
|
386
|
my ($K) = @_; |
51
|
1
|
|
|
1
|
|
24
|
sub { $K }} |
|
1
|
|
|
|
|
5
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
## ---------------------------------------------- |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
## short circut function compositors |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub disjoin ($$) { |
58
|
2
|
|
|
2
|
1
|
16
|
my ($f, $f2) = @_; |
59
|
2
|
100
|
|
3
|
|
12
|
sub { $f->(@_) || $f2->(@_) }} |
|
3
|
|
|
|
|
7
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub conjoin ($$) { |
62
|
3
|
|
|
3
|
1
|
4
|
my ($f, $f2) = @_; |
63
|
3
|
100
|
|
4
|
|
17
|
sub { $f->(@_) && $f2->(@_) }} |
|
4
|
|
|
|
|
12
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# this method is really more a utility method |
68
|
|
|
|
|
|
|
# to go along with these other, it can be used |
69
|
|
|
|
|
|
|
# to bind a anyonomous function to a symbol within |
70
|
|
|
|
|
|
|
# the callers namespace |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub defun ($$) { |
73
|
6
|
|
|
6
|
1
|
12
|
my ($symbol, $f) = @_; |
74
|
1
|
|
|
1
|
|
14
|
no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
122
|
|
75
|
6
|
|
|
|
|
7
|
*{(caller())[0] . "::$symbol"} = $f } |
|
6
|
|
|
|
|
37
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |