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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
run: "composer normalize --ansi --dry-run"

- name: "Cache cache directory for easy-coding-standard/easy-coding-standard"
uses: "actions/cache@v4.0.2"
uses: "actions/cache@v4"
with:
path: ".build/ecs"
key: "php-${{ matrix.php-version }}-ecs-${{ github.ref_name }}"
Expand Down
36 changes: 21 additions & 15 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ abstract public function err(): Option;
*
* @template U
*
* @param callable(T=):U $mapper
* @param callable(T):U $mapper
* @return Result<U,E>
*/
abstract public function map(callable $mapper): self;
Expand All @@ -72,7 +72,7 @@ abstract public function map(callable $mapper): self;
* @template U
*
* @param U $default
* @param callable(T=):U $f
* @param callable(T):U $f
*
* @return U
*/
Expand All @@ -83,8 +83,8 @@ abstract public function mapOr($default, callable $f): mixed;
*
* @template U
*
* @param callable(E=):U $default
* @param callable(T=):U $f
* @param callable(E):U $default
* @param callable(T):U $f
*
* @return U
*/
Expand All @@ -95,15 +95,15 @@ abstract public function mapOrElse(callable $default, callable $f): mixed;
*
* @template F
*
* @param callable(E=):F $op
* @param callable(E):F $op
* @return Result<T,F>
*/
abstract public function mapErr(callable $op): self;

/**
* Calls a function with a reference to the contained value if Ok.
*
* @param callable(T=):void $f
* @param callable(T):void $f
*
* @return Result<T,E>
*/
Expand All @@ -112,7 +112,7 @@ abstract public function inspect(callable $f): self;
/**
* Calls a function with a reference to the contained value if Err.
*
* @param callable(E=):void $f
* @param callable(E):void $f
*
* @return Result<T,E>
*/
Expand Down Expand Up @@ -172,9 +172,10 @@ abstract public function and(self $res): self;
* Calls op if the result is Ok, otherwise returns the Err value of self.
*
* @template U
* @template F
*
* @param callable(T=):Result<U,E> $op
* @return Result<U,E>
* @param callable(T):Result<U,F> $op
* @return Result<U,E|F>
*/
abstract public function andThen(callable $op): self;

Expand All @@ -191,26 +192,31 @@ abstract public function or(self $res): self;
/**
* Calls op if the result is Err, otherwise returns the Ok value of self.
*
* @template U
* @template F
*
* @param callable(E=):Result<T,F> $op
* @return Result<T,F>
* @param callable(E):Result<U,F> $op
* @return Result<T|U,F>
*/
abstract public function orElse(callable $op): self;

/**
* Unwraps a result, yielding the content of an Ok. Else, it returns optb.
*
* @param T $optb
* @return T
* @template U
*
* @param U $optb
* @return T|U
*/
abstract public function unwrapOr($optb): mixed;

/**
* Unwraps a result, yielding the content of an Ok. If the value is an Err then it calls op with its value.
*
* @param callable(E=):T $op
* @return T
* @template U
*
* @param callable(E):U $op
* @return T|U
*/
abstract public function unwrapOrElse(callable $op): mixed;
}