Skip to content

Commit 0bbb9a7

Browse files
committed
slight perf with early return
1 parent 2be5f1c commit 0bbb9a7

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

packages/fpdart/lib/src/extension/iterable_extension.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,12 @@ extension FpdartOnIterable<T> on Iterable<T> {
429429
Option<T> singleWhereOption(bool Function(T element) test) {
430430
T? result;
431431
var found = false;
432+
432433
for (final element in this) {
433434
if (test(element)) {
434-
if (!found) {
435-
result = element;
436-
found = true;
437-
} else {
438-
result = null;
439-
break;
440-
}
435+
if (found) return const Option.none();
436+
result = element;
437+
found = true;
441438
}
442439
}
443440

0 commit comments

Comments
 (0)