-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
134 additions
and
5 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 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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Doc\DocLinker; | ||
|
||
require_once 'vendor/autoload.php'; | ||
|
||
$linker = new DocLinker(); | ||
$linker->link(__DIR__ . '/src/Doc/Md/*/'); | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Callable | ||
- #### compose | ||
Compose functions | ||
|
||
Output of one function will be passed as input to another function | ||
|
||
```php | ||
$aToB = fn(int $a): bool => true; | ||
$bToC = fn(bool $b): string => (string) $b; | ||
$cTod = fn(string $c): float => (float) $c; | ||
|
||
/** @var callable(int): float $result */ | ||
$result = \Fp\Callable\compose($aToB, $bToC, $cTod); | ||
``` | ||
|
||
- #### partial and partialLeft | ||
Partial application from first function argument | ||
|
||
```php | ||
$callback = fn(int $a, string $b, bool $c): bool => true; | ||
|
||
/** @var callable(bool): bool $result */ | ||
$result = \Fp\Callable\partial($callback, 1, "string"); | ||
|
||
/** @var callable(bool): bool $result */ | ||
$result = \Fp\Callable\partialLeft($callback, 1, "string"); | ||
``` | ||
|
||
- #### partialRight | ||
Partial application from last function argument | ||
|
||
```php | ||
$callback = fn(int $a, string $b, bool $c): bool => true; | ||
|
||
/** @var callable(int): bool $result */ | ||
$result = \Fp\Callable\partialRight($callback, true, "string"); | ||
``` |
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,74 @@ | ||
# Cast | ||
- #### asArray | ||
Copy collection as array | ||
|
||
```php | ||
/** @psalm-return iterable<string, int> */ | ||
function getCollection(): array { return []; } | ||
|
||
/** @var array<string, int> $result */ | ||
$result = asArray(getCollection()); | ||
``` | ||
|
||
- #### asBool | ||
Try cast boolean like value | ||
|
||
Returns None if cast is not possible | ||
|
||
```php | ||
/** @var Option<bool> $result */ | ||
$result = asBool('yes'); | ||
``` | ||
|
||
- #### asFloat | ||
Try cast float like value | ||
|
||
Returns None if cast is not possible | ||
|
||
```php | ||
/** @var Option<float> $result */ | ||
$result = asFloat('1.1'); | ||
``` | ||
|
||
- #### asInt | ||
Try cast integer like value | ||
|
||
Returns None if cast is not possible | ||
|
||
```php | ||
/** @var Option<int> $result */ | ||
$result = asInt(1); | ||
``` | ||
|
||
- #### asList | ||
Copy one or multiple collections as list | ||
|
||
```php | ||
$result = asList([1], ['prop' => 2], [3, 4]); // [1, 2, 3, 4] | ||
``` | ||
|
||
- #### asNonEmptyArray | ||
Try copy and cast collection to non-empty-array | ||
|
||
Returns None if there is no first collection element | ||
|
||
```php | ||
/** @psalm-return iterable<string, int> */ | ||
function getCollection(): array { return []; } | ||
|
||
/** @var Option<non-empty-array<string, int>> $result */ | ||
$result = asNonEmptyArray(getCollection()); | ||
``` | ||
|
||
- #### asNonEmptyList | ||
Try copy and cast collection to non-empty-list | ||
|
||
Returns None if there is no first collection element | ||
|
||
```php | ||
/** @psalm-return iterable<string, int> */ | ||
function getCollection(): array { return []; } | ||
|
||
/** @var Option<non-empty-list<int>> $result */ | ||
$result = asNonEmptyList(getCollection()); | ||
``` |