Skip to content
Merged
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
18 changes: 11 additions & 7 deletions src/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,20 @@ abstract public function unwrap();
/**
* Unwraps a result, yielding the content of a Some. Else, it returns optb.
*
* @param T $optb
* @return T
* @template U
*
* @param U $optb
* @return T|U
*/
abstract public function unwrapOr($optb);

/**
* Returns the contained value or computes it from a callable.
*
* @param callable(): T $op
* @return T
* @template U
*
* @param callable(): U $op
* @return T|U
Comment on lines +61 to +74
Copy link

Choose a reason for hiding this comment

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

This change will make it behave differently from the Rust implementation. It looks like the these methods there return the same type of value as contained in the Option itself. Here are the docs for reference. So I think this should be as it was before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Imho it doesn't have to slavishly like Rust, this makes it more flexible. Rust has much better language level constructs to handle Options/Results, so a bit of leeway is, I think, acceptable.

Copy link
Owner

Choose a reason for hiding this comment

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

I agree with this reasoning FWIW, the goal of the lib is to deliver value to the PHP language.

*/
abstract public function unwrapOrElse(callable $op);

Expand All @@ -84,7 +88,7 @@ abstract public function inspect(callable $f): self;
*
* @template U
*
* @param callable(T=):U $mapper
* @param callable(T):U $mapper
* @return Option<U>
*/
abstract public function map(callable $mapper): self;
Expand All @@ -95,7 +99,7 @@ abstract public function map(callable $mapper): self;
* @template U
*
* @param U $default
* @param callable(T=):U $mapper
* @param callable(T):U $mapper
* @return U
*/
abstract public function mapOr($default, callable $mapper);
Expand All @@ -106,7 +110,7 @@ abstract public function mapOr($default, callable $mapper);
* @template U
*
* @param callable():U $default
* @param callable(T=):U $mapper
* @param callable(T):U $mapper
* @return U
*/
abstract public function mapOrElse(callable $default, callable $mapper);
Expand Down
Loading