-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* develop: specify next release bump psalm version add Frame::filter add frames add Stream::unwrap() flag pure code
- Loading branch information
Showing
20 changed files
with
1,000 additions
and
20 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
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 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 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,51 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Innmind\IO\Readable; | ||
|
||
use Innmind\Immutable\{ | ||
Maybe, | ||
Str, | ||
}; | ||
|
||
/** | ||
* @template T | ||
*/ | ||
interface Frame | ||
{ | ||
/** | ||
* @param callable(?positive-int): Maybe<Str> $read | ||
* @param callable(): Maybe<Str> $readLine | ||
* | ||
* @return Maybe<T> | ||
*/ | ||
public function __invoke( | ||
callable $read, | ||
callable $readLine, | ||
): Maybe; | ||
|
||
/** | ||
* @param callable(T): bool $predicate | ||
* | ||
* @return self<T> | ||
*/ | ||
public function filter(callable $predicate): self; | ||
|
||
/** | ||
* @template U | ||
* | ||
* @param callable(T): U $map | ||
* | ||
* @return self<U> | ||
*/ | ||
public function map(callable $map): self; | ||
|
||
/** | ||
* @template U | ||
* | ||
* @param callable(T): self<U> $map | ||
* | ||
* @return self<U> | ||
*/ | ||
public function flatMap(callable $map): self; | ||
} |
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,57 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Innmind\IO\Readable\Frame; | ||
|
||
use Innmind\IO\Readable\Frame; | ||
use Innmind\Immutable\{ | ||
Maybe, | ||
Str, | ||
}; | ||
|
||
/** | ||
* @implements Frame<Str> | ||
*/ | ||
final class Chunk implements Frame | ||
{ | ||
/** @var positive-int */ | ||
private int $size; | ||
|
||
/** | ||
* @param positive-int $size | ||
*/ | ||
private function __construct(int $size) | ||
{ | ||
$this->size = $size; | ||
} | ||
|
||
public function __invoke( | ||
callable $read, | ||
callable $readLine, | ||
): Maybe { | ||
return $read($this->size); | ||
} | ||
|
||
/** | ||
* @param positive-int $size | ||
*/ | ||
public static function of(int $size): self | ||
{ | ||
return new self($size); | ||
} | ||
|
||
public function filter(callable $predicate): Frame | ||
{ | ||
return Filter::of($this, $predicate); | ||
} | ||
|
||
public function map(callable $map): Frame | ||
{ | ||
return Map::of($this, $map); | ||
} | ||
|
||
public function flatMap(callable $map): Frame | ||
{ | ||
return FlatMap::of($this, $map); | ||
} | ||
} |
Oops, something went wrong.