Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"src/Functional/Memoize.php",
"src/Functional/Minimum.php",
"src/Functional/None.php",
"src/Functional/Noop.php",
"src/Functional/Not.php",
"src/Functional/PartialAny.php",
"src/Functional/PartialLeft.php",
Expand Down
10 changes: 8 additions & 2 deletions docs/functional-php.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
- [id()](#id)
- [tap()](#tap)
- [repeat()](#repeat)
- [noop()](#noop)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -1045,7 +1046,6 @@ $one = const_function(1);
$one(); // -> 1
```


## id()
Proxy function that does nothing except returning its first argument.

Expand Down Expand Up @@ -1079,4 +1079,10 @@ use function Functional\repeat;
repeat(function () {
echo 'foo';
})(3); // 'foofoofoo'
```
```

## noop()

A no-operation function, i.e. a function that does nothing.

``void Functional\noop()``
5 changes: 5 additions & 0 deletions src/Functional/Functional.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ final class Functional
*/
const none = '\Functional\none';

/**
* @see \Functional\noop
*/
const noop = '\Functional\noop';

/**
* @see \Functional\not
*/
Expand Down
30 changes: 30 additions & 0 deletions src/Functional/Noop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Copyright (C) 2011-2017 by Lars Strojny <lstrojny@php.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace Functional;

/**
* A no-operation function.
*/
function noop()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the return type be void or null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be void as it does nothing?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking it would then be illegal to use it in a map

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will always be an illegal case for any return type, right? 🤔

{
}