···140| `$fn` | **callable** | Function to transform the value |
141142***
00000000000000000
···140| `$fn` | **callable** | Function to transform the value |
141142***
143+144+### mapOr
145+146+Calls `fn` on a contained value if `some`, or returns $or if `none`
147+148+```php
149+public mapOr(mixed $or, callable $fn): \Ciarancoza\OptionResult\V|\Ciarancoza\OptionResult\U
150+```
151+152+**Parameters:**
153+154+| Parameter | Type | Description |
155+|-----------|--------------|---------------------------------|
156+| `$or` | **mixed** | |
157+| `$fn` | **callable** | Function to transform the value |
158+159+***
+17
docs/classes/Ciarancoza/OptionResult/Result.md
···198199***
20000000000000000000201### mapErr
202203If `err`, transform the error value with `$fn`
···198199***
200201+### mapOr
202+203+Calls `fn` on a contained value if `ok`, or returns $or if `err`
204+205+```php
206+public mapOr(mixed $or, callable $fn): \Ciarancoza\OptionResult\V|\Ciarancoza\OptionResult\U
207+```
208+209+**Parameters:**
210+211+| Parameter | Type | Description |
212+|-----------|--------------|---------------------------------|
213+| `$or` | **mixed** | |
214+| `$fn` | **callable** | Function to transform the value |
215+216+***
217+218### mapErr
219220If `err`, transform the error value with `$fn`
···104105 return Option::Some($fn($this->value));
106 }
107+108+ /**
109+ * Calls `fn` on a contained value if `some`, or returns $or if `none`
110+ *
111+ * @template V $or
112+ * @template U
113+ *
114+ * @param callable(T): U $fn Function to transform the value
115+ * @return V|U
116+ */
117+ public function mapOr(mixed $or, callable $fn): mixed
118+ {
119+ return match (true) {
120+ $this->isSome() => $fn($this->unwrap()),
121+ $this->isNone() => is_callable($or) ? $or() : $or,
122+ };
123+ }
124}
+17
src/Result.php
···161 }
162163 /**
00000000000000000164 * If `err`, transform the error value with `$fn`
165 *
166 * @template U
···161 }
162163 /**
164+ * Calls `fn` on a contained value if `ok`, or returns $or if `err`
165+ *
166+ * @template V $or
167+ * @template U
168+ *
169+ * @param callable(T): U $fn Function to transform the value
170+ * @return V|U
171+ */
172+ public function mapOr(mixed $or, callable $fn): mixed
173+ {
174+ return match (true) {
175+ $this->isOk() => $fn($this->unwrap()),
176+ $this->isErr() => is_callable($or) ? $or() : $or,
177+ };
178+ }
179+180+ /**
181 * If `err`, transform the error value with `$fn`
182 *
183 * @template U
+3-1
tests/OptionTest.php
···6061 public function test_map_or(): void
62 {
63- $this->markTestIncomplete('TODO');
64 $this->assertSame(3, Option::Some('foo')->mapOr(42, fn ($v) => strlen($v)));
65 $this->assertSame(42, Option::None()->mapOr(42, fn ($v) => strlen($v)));
00066 }
6768 public function test_map_or_else(): void