We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Option::apply()
1 parent 4affb62 commit 4318a1dCopy full SHA for 4318a1d
src/Psl/Option/Option.php
@@ -199,6 +199,22 @@ public function contains(mixed $value): bool
199
return false;
200
}
201
202
+ /**
203
+ * Applies a function to a contained value and returns the original `Option<T>`.
204
+ *
205
+ * @param (Closure(T): void) $closure
206
207
+ * @return Option<T>
208
+ */
209
+ public function apply(Closure $closure): Option
210
+ {
211
+ if ($this->option !== null) {
212
+ $closure($this->option[0]);
213
+ }
214
+
215
+ return $this;
216
217
218
/**
219
* Maps an `Option<T>` to `Option<Tu>` by applying a function to a contained value.
220
*
0 commit comments