refactor: implement suggestions

This commit is contained in:
Yaros
2026-05-08 15:59:41 +02:00
parent 7956756d38
commit 12c4ee83d6
6 changed files with 96 additions and 59 deletions
+15
View File
@@ -24,6 +24,21 @@ sealed class Option<T> {
None() => onNone(),
};
Option<U> flatMap<U>(Option<U> Function(T value) f) => switch (this) {
Some(:final value) => f(value),
None() => const Option.none(),
};
void ifSome(void Function(T value) action) {
switch (this) {
case Some(:final value):
action(value);
break;
case None():
break;
}
}
@override
String toString() => switch (this) {
Some(:final value) => 'Some($value)',