-
-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathUnless.php
More file actions
32 lines (27 loc) · 782 Bytes
/
Copy pathUnless.php
File metadata and controls
32 lines (27 loc) · 782 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
<?php
/**
* @package Functional-php
* @author Lars Strojny <lstrojny@php.net>
* @copyright 2011-2021 Lars Strojny
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/lstrojny/functional-php
*/
namespace Functional;
/**
* Return a value if the given condition is false.
*
* @param mixed|\Closure $condition
* @param mixed|\Closure $value
* @param mixed|\Closure $default
*
* @return mixed
* @no-named-arguments
*/
function unless($condition, $value, $default = null)
{
$condition = $condition instanceof \Closure ? $condition() : $condition;
if (!$condition) {
return $value instanceof \Closure ? $value($condition) : $value;
}
return $default instanceof \Closure ? $default($condition) : $default;
}