@@ -36,16 +36,16 @@ function none(): Option\None
36
36
* It will be a `Some` option containing `$value` if `$value` is different from `$noneValue` (default `null`)
37
37
*
38
38
* @template U
39
- * @param U|null $value
40
- * @return Option<U>
39
+ * @template NoneValue
40
+ *
41
+ * @param U $value
42
+ * @param NoneValue|null $noneValue
43
+ *
44
+ * @return ($noneValue is null ? Option<U> : Option<U|NoneValue>)
41
45
*/
42
- function fromValue ($ value , mixed $ noneValue = null , bool $ strict = true ): Option
46
+ function fromValue ($ value , mixed $ noneValue = null ): Option
43
47
{
44
- $ same = $ strict
45
- ? ($ value === $ noneValue )
46
- : ($ value == $ noneValue );
47
-
48
- return $ same
48
+ return $ value === $ noneValue
49
49
? Option \none ()
50
50
: Option \some ($ value );
51
51
}
@@ -55,33 +55,41 @@ function fromValue($value, mixed $noneValue = null, bool $strict = true): Option
55
55
* It will be a `Some` option containing the result if it is different from `$noneValue` (default `null`).
56
56
*
57
57
* @template U
58
- * @param callable():U|null $callback
59
- * @return Option<U>
58
+ * @template NoneValue
59
+ *
60
+ * @param callable():U $callback
61
+ * @param NoneValue|null $noneValue
62
+ *
63
+ * @return ($noneValue is null ? Option<U> : Option<U|NoneValue>)
60
64
*/
61
- function of (callable $ callback , mixed $ noneValue = null , bool $ strict = true ): Option
65
+ function of (callable $ callback , mixed $ noneValue = null ): Option
62
66
{
63
- return Option \fromValue ($ callback (), $ noneValue, $ strict );
67
+ return Option \fromValue ($ callback (), $ noneValue );
64
68
}
65
69
66
70
/**
67
71
* Execute a callable and transform the result into an `Option` as `Option\of()` does
68
72
* but also return `Option\None` if it an exception matching $exceptionClass was thrown.
69
73
*
70
74
* @template U
75
+ * @template NoneValue
71
76
* @template E of \Throwable
72
- * @param callable():U|null $callback
73
- * @param class-string<E> $exceptionClass
74
- * @return Option<U>
77
+ *
78
+ * @param callable():U $callback
79
+ * @param NoneValue|null $noneValue
80
+ * @param class-string<E> $exceptionClass
81
+ *
82
+ * @return ($noneValue is null ? Option<U> : Option<U|NoneValue>)
83
+ *
75
84
* @throws Throwable
76
85
*/
77
86
function tryOf (
78
87
callable $ callback ,
79
88
mixed $ noneValue = null ,
80
- bool $ strict = true ,
81
89
string $ exceptionClass = Exception::class,
82
90
): Option {
83
91
try {
84
- return Option \of ($ callback , $ noneValue, $ strict );
92
+ return Option \of ($ callback , $ noneValue );
85
93
} catch (Throwable $ th ) {
86
94
if (is_a ($ th , $ exceptionClass )) {
87
95
return Option \none ();
@@ -95,7 +103,8 @@ function tryOf(
95
103
* Converts from `Option<Option<T>>` to `Option<T>`.
96
104
*
97
105
* @template U
98
- * @param Option<Option<U>> $option
106
+ * @param Option<Option<U>> $option
107
+ *
99
108
* @return Option<U>
100
109
*/
101
110
function flatten (Option $ option ): Option
@@ -113,7 +122,9 @@ function flatten(Option $option): Option
113
122
*
114
123
* @template U
115
124
* @template E
116
- * @param Option<Result<U, E>> $option
125
+ *
126
+ * @param Option<Result<U, E>> $option
127
+ *
117
128
* @return Result<Option<U>, E>
118
129
*/
119
130
function transpose (Option $ option ): Result
0 commit comments