-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsession3.php
More file actions
39 lines (31 loc) · 965 Bytes
/
session3.php
File metadata and controls
39 lines (31 loc) · 965 Bytes
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
<?php
declare(strict_types=1);
class HigherOrderFunctionSession
{
public static function handle()
{
$closureOne = fn ($x) => self::testOne($x);
$closureTwo = fn ($x) => self::testTwo($x);
$closureThree = fn ($x, $y) => self::testThree($x, $y);
$closureList = [$closureOne, $closureTwo];
echo $closureTwo($closureOne(5)).PHP_EOL;
echo $closureOne($closureTwo(5)).PHP_EOL;
echo $closureList[0](5).PHP_EOL;
echo $closureList[1](5).PHP_EOL;
echo $closureThree($closureOne, 5).PHP_EOL;
echo $closureThree($closureTwo, 5).PHP_EOL;
}
public static function testOne(float $x) : float
{
return $x / 2;
}
public static function testTwo(float $x) : float
{
return $x / 4 + 1;
}
public static function testThree(Closure $f, float $value) : float
{
return $f($value) + $value;
}
}
HigherOrderFunctionSession::handle();