You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This returns an [`Attempt`](attempt.md) containing the right value, in case of a left value it returns an `Attempt` with the error provided by the callable inside.
192
+
193
+
```php
194
+
Either::right('something')
195
+
->attempt(static fn() => new \Exception)
196
+
->unwrap(); // returns 'something'
197
+
Either::left('something')
198
+
->attempt(static fn(string $left) => new \Exception($left))
199
+
->unwrap(); // throws new \Exception('something')
200
+
```
201
+
189
202
## `->memoize()`
190
203
191
204
This method force to load the contained value into memory. This is only useful for a deferred `Either`, this will do nothing for other either as the value is already known.
Copy file name to clipboardExpand all lines: docs/structures/maybe.md
+13Lines changed: 13 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -166,6 +166,19 @@ Maybe::nothing()
166
166
); // return 'something'
167
167
```
168
168
169
+
## `->either()`
170
+
171
+
This returns an [`Attempt`](attempt.md) containing the value as a result and the error is provided by the callable.
172
+
173
+
```php
174
+
Maybe::just('something')
175
+
->attempt(static fn() => new \Exception)
176
+
->unwrap(); // returns 'something'
177
+
Maybe::nothing()
178
+
->attempt(static fn() => new \Exception)
179
+
->unwrap(); // throws the exception
180
+
```
181
+
169
182
## `->memoize()`
170
183
171
184
This method force to load the contained value into memory. This is only useful for a deferred `Maybe`, this will do nothing for other maybe as the value is already known.
0 commit comments