Completed
Pull Request — master (#14)
by Paweł
02:24
created

Delayed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace {
6
    require_once __DIR__.'/Conversion/implicit_conversion.php';
7
    require_once __DIR__.'/PatternMatching/functions.php';
8
    require_once __DIR__.'/Reflection/functions.php';
9
    require_once __DIR__.'/Type/restrictions.php';
10
    require_once __DIR__.'/Utils/functions.php';
11
}
12
13
namespace Scalp {
14
    use function Scalp\Conversion\AnyToString;
15
16
    const identity = __NAMESPACE__.'\identity';
17
18
    function identity($x)
19
    {
20
        return $x;
21
    }
22
23
    const concat = __NAMESPACE__.'\concat';
24
25
    function concat(string ...$strings): string
26
    {
27
        return implode('', $strings);
28
    }
29
30
    const inc = __NAMESPACE__.'\inc';
31
32
    function inc(int $x, int $step = 1): int
33
    {
34
        return $x + $step;
35
    }
36
37
    const throwE = __NAMESPACE__.'\throwE';
38
39
    function throwE(string $class, string $message): void
40
    {
41
        throw new $class($message);
42
    }
43
44
    const println = __NAMESPACE__.'\println';
45
46
    function println($x): void
47
    {
48
        echo AnyToString($x)."\n";
49
    }
50
51
    const None = __NAMESPACE__.'\None';
52
53
    function None(): None
54
    {
55
        return new None();
56
    }
57
58
    const Some = __NAMESPACE__.'\Some';
59
60
    function Some($x): Some
61
    {
62
        return new Some($x);
63
    }
64
65
    function Option($x): Option
66
    {
67
        return ($x === null) ? None() : Some($x);
68
    }
69
70
    const __ = '$argument$';
71
72
    function papply(callable $f, ...$args): callable
73
    {
74
        return new PartialApplication($f, $args);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Scalp\PartialApplication($f, $args) returns the type Scalp\PartialApplication which is incompatible with the type-hinted return callable.
Loading history...
75
    }
76
77
    function Pair($_1, $_2): Tuple
78
    {
79
        return new Tuple($_1, $_2);
80
    }
81
82
    function Tuple(...$elements): Tuple
83
    {
84
        return new Tuple(...$elements);
85
    }
86
}
87
88
namespace Scalp\Conversion {
89
    const AnyToString = __NAMESPACE__.'\AnyToString';
90
91
    function AnyToString($any): string
92
    {
93
        static $anyToString = null;
94
95
        if ($anyToString === null) {
96
            $anyToString = new AnyToString();
97
        }
98
99
        return $anyToString($any);
100
    }
101
}
102