invert()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Dryist;
4
5
/**
6
 * Create a modifier that always returns the same value.
7
 *
8
 * Also known as the Kestrel or "K" combinator.
9
 *
10
 * @see https://en.wikipedia.org/wiki/SKI_combinator_calculus
11
 *
12
 * @param mixed $x
13
 * @return callable () => x
14
 */
15
function always($x): callable
16
{
17
    return function () use ($x) {
18 1
        return $x;
19 1
    };
20
}
21
const always = '\Dryist\always';
22
23
/**
24
 * Create a composition of two modifiers.
25
 *
26
 * Also known as the Substition or "S" combinator.
27
 *
28
 * @return callable (z) => x(y(z))
29
 */
30
function compose(callable $x, callable $y): callable
31
{
32
    return function ($z) use ($x, $y) {
33 1
        return $x($y($z));
34 1
    };
35
}
36
const compose = '\Dryist\compose';
37
38
/**
39
 * @alias identity()
40
 */
41
function id($x)
42
{
43 1
    return identity($x);
44
}
45
const id = '\Dryist\identity';
46
47
/**
48
 * Return any given variable.
49
 *
50
 * Also known as the Identity or "I" combinator.
51
 *
52
 * @see https://en.wikipedia.org/wiki/SKI_combinator_calculus
53
 *
54
 * @param mixed $x
55
 * @return mixed The value of $x
56
 */
57
function identity($x)
58
{
59 1
    return $x;
60
}
61
const identity = '\Dryist\identity';
62
63
/**
64
 * Create a negated predicate.
65
 *
66
 * @return callable (y) => ! x(y)
67
 */
68
function invert(callable $x): callable
69
{
70
    return function ($y) use ($x): bool {
71 1
        return ! $x($y);
72 1
    };
73
}
74
const invert = '\Dryist\invert';
75