-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed constant function name to identity
- Loading branch information
Showing
7 changed files
with
62 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# identity | ||
|
||
## Description | ||
|
||
It wraps a value into a closure, which return the same value that is passed as argument whenever is called. | ||
|
||
## Parameters | ||
|
||
<dl> | ||
<dt>value</dt> | ||
<dd>Any type of value that will be returned</dd> | ||
</dl> | ||
|
||
## Examples | ||
|
||
Fill an array with zeros: | ||
|
||
```php | ||
<?php | ||
|
||
use function Lambdish\Phunctional\map; | ||
use function Lambdish\Phunctional\identity; | ||
|
||
$numbers = [1,2,3,4,5]; | ||
|
||
map(identity(0), $numbers); | ||
|
||
// => [0,0,0,0,0] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Lambdish\Phunctional\Tests; | ||
|
||
use PHPUnit_Framework_TestCase; | ||
use function Lambdish\Phunctional\identity; | ||
|
||
final class IdentityTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** @test */ | ||
public function it_should_return_a_value() | ||
{ | ||
$value = 5; | ||
$identityClosure = identity($value); | ||
|
||
$this->assertSame($value, $identityClosure()); | ||
} | ||
|
||
/** @test */ | ||
public function it_should_return_same_value_if_called_twice() | ||
{ | ||
$value = 5; | ||
$identityClosure = identity($value); | ||
|
||
$identityClosure(); | ||
|
||
$this->assertSame($value, $identityClosure()); | ||
} | ||
} |