-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathHead.php
More file actions
47 lines (40 loc) · 653 Bytes
/
Copy pathHead.php
File metadata and controls
47 lines (40 loc) · 653 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
40
41
42
43
44
45
46
47
<?php
/**
* head function
*
* @package bingo-functional
* @author Lochemem Bruno Michael
* @license Apache-2.0
*/
namespace Chemem\Bingo\Functional;
const head = __NAMESPACE__ . '\\head';
/**
* head
* Outputs the first element in a list
*
* head :: [a] -> a -> a
*
* @param object|array $list
* @param mixed $default
* @return mixed
* @example
*
* head(range(4, 7))
* => 4
*/
function head($list, $default = null)
{
if (
!(
\is_object($list) ||
\is_array($list)
)
) {
return $default;
}
\reset($list);
$result = \current($list);
return equals($result, false) ?
$default :
$result;
}