Skip to content

Commit

Permalink
chore(result): move Async\reflect to Result\reflect
Browse files Browse the repository at this point in the history
  • Loading branch information
azjezz committed Jan 15, 2022
1 parent bfbdef7 commit 21bf0cd
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@
* **BC** - function `Psl\Password\algorithms()` have been removed.
* **BC** - `Psl\Result\ResultInterface::getException()` method has been renamed to `Psl\Result\ResultInterface::getThrowable()`
* **BC** - `Psl\Result\wrap` function now catches all `Throwable`s instead of only `Exception`s

* introduced a new `Psl\Result\reflect` function
1 change: 0 additions & 1 deletion docs/component/async.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
- [first](./../../src/Psl/Async/first.php#L20)
- [later](./../../src/Psl/Async/later.php#L14)
- [main](./../../src/Psl/Async/main.php#L18)
- [reflect](./../../src/Psl/Async/reflect.php#L25)
- [run](./../../src/Psl/Async/run.php#L19)
- [series](./../../src/Psl/Async/series.php#L21)
- [sleep](./../../src/Psl/Async/sleep.php#L10)
Expand Down
1 change: 1 addition & 0 deletions docs/component/result.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#### `Functions`

- [reflect](./../../src/Psl/Result/reflect.php#L24)
- [wrap](./../../src/Psl/Result/wrap.php#L20)

#### `Interfaces`
Expand Down
28 changes: 0 additions & 28 deletions src/Psl/Async/reflect.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Psl/Internal/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ final class Loader
'Psl\Async\main',
'Psl\Async\run',
'Psl\Async\concurrently',
'Psl\Async\reflect',
'Psl\Result\reflect',
'Psl\Async\series',
'Psl\Async\await',
'Psl\Async\any',
Expand Down
27 changes: 27 additions & 0 deletions src/Psl/Result/reflect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Psl\Result;

use Closure;
use Throwable;

/**
* Wraps the given operation in another operation that always completes with a {@see Success},
* or {@see Failure} if the closure throws an {@see Throwable}.
*
* @template T
*
* @param Closure(): T $task
*
* @return Closure(): ResultInterface<T>
*
* @see wrap()
*
* @pure
*/
function reflect(Closure $task): Closure
{
return static fn() => wrap($task);
}
4 changes: 2 additions & 2 deletions tests/unit/Async/ReflectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ final class ReflectTest extends TestCase
public function testReflectParallel(): void
{
[$one, $two] = Async\concurrently([
Async\reflect(static function (): void {
Result\reflect(static function (): void {
Async\sleep(0.0001);

throw new Exception('failure');
}),
Async\reflect(static function (): string {
Result\reflect(static function (): string {
return 'success';
}),
]);
Expand Down

0 comments on commit 21bf0cd

Please sign in to comment.