Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
  • Loading branch information
ghostwriter committed Apr 25, 2023
1 parent be01fa2 commit f6ab1c1
Showing 1 changed file with 32 additions and 27 deletions.
59 changes: 32 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ divide(1, 1); // Some(1)
/**
* @immutable
*
* @implements OptionInterface<TValue>
* @template TSome
*
* @template TValue
* @extends OptionInterface<TSome>
*/
interface SomeInterface extends OptionInterface
{
/**
* @template TSomeValue
* @template TValue
*
* @param TSomeValue $value
* @param TValue $value
*
* @return self<TSomeValue>
* @return self<TValue>
*/
public static function create(mixed $value): self;
}
Expand All @@ -81,13 +81,13 @@ interface SomeInterface extends OptionInterface
/**
* @immutable
*
* @implements OptionInterface<TValue>
* @template TNone of null
*
* @template TValue
* @extends OptionInterface<TNone>
*/
interface NoneInterface extends OptionInterface
{
/** @return self<TValue> */
/** @return self<TNone> */
public static function create(): self;
}
```
Expand All @@ -96,14 +96,22 @@ interface NoneInterface extends OptionInterface

``` php
/**
* @implements IteratorAggregate<TValue>
* @immutable
*
* @template TValue
*
* @extends IteratorAggregate<int,TValue>
*/
interface OptionInterface extends IteratorAggregate
{
/**
* Returns None if the Option is None, otherwise returns $option.
*
* @template TAnd
*
* @param self<TAnd> $option
*
* @return self<TAnd|TValue>
*/
public function and(self $option): self;

Expand All @@ -112,7 +120,7 @@ interface OptionInterface extends IteratorAggregate
*
* @template TAndThen
*
* @param callable(TValue):self $function
* @param callable(TValue):TAndThen $function
*
* @return self<TAndThen|TValue>
*/
Expand All @@ -121,7 +129,9 @@ interface OptionInterface extends IteratorAggregate
/**
* Returns true if the option is a Some value containing the given $value.
*
* @param TValue $value
* @template TContainsValue
*
* @param TContainsValue $value
*/
public function contains(mixed $value): bool;

Expand Down Expand Up @@ -151,7 +161,7 @@ interface OptionInterface extends IteratorAggregate
*/
public function flatten(): self;

public function getIterator(): Traversable;
public function getIterator(): Generator;

/**
* Returns true if the Option is an instance of None.
Expand All @@ -170,7 +180,7 @@ interface OptionInterface extends IteratorAggregate
*
* @param callable(TValue):TMap $function
*
* @return self<TMap>
* @return self<TMap|TValue>
*/
public function map(callable $function): self;

Expand Down Expand Up @@ -200,24 +210,17 @@ interface OptionInterface extends IteratorAggregate
*/
public function mapOrElse(callable $function, callable $fallback): mixed;

/**
* Creates an option with the given value.
*
* By default, we treat null as the None case, and everything else as Some.
*
* @template TNullableValue
*
* @param TNullableValue $value the actual value
*
* @return self<TNullableValue|TValue>
*/
public static function of(mixed $value): self;

/**
* Returns the option if it contains a value, otherwise returns $option.
*
* Arguments passed to or are eagerly evaluated; if you are passing the result of a function call, it is recommended
* to use orElse, which is lazily evaluated.
*
* @template TOr
*
* @param self<TOr> $option
*
* @return self<TOr|TValue>
*/
public function or(self $option): self;

Expand All @@ -226,7 +229,9 @@ interface OptionInterface extends IteratorAggregate
*
* @template TCallableResultValue
*
* @param callable(): OptionInterface<TCallableResultValue> $function
* @param callable(): self<TCallableResultValue> $function
*
* @return self<TCallableResultValue|TValue>
*/
public function orElse(callable $function): self;

Expand Down

0 comments on commit f6ab1c1

Please sign in to comment.