Skip to content

Commit

Permalink
Allow letOrNull to return R?
Browse files Browse the repository at this point in the history
  • Loading branch information
passsy committed Aug 30, 2024
1 parent 690afad commit 0eb077d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/pick_let.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension NullableLet on Pick {
/// user = User.fromJson(pick.asMap());
/// }
/// ```
R? letOrNull<R>(R Function(RequiredPick pick) block) {
R? letOrNull<R>(R? Function(RequiredPick pick) block) {
if (value == null) return null;
return block(required());
}
Expand Down
4 changes: 4 additions & 0 deletions test/src/pick_let_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ void main() {
Person(name: 'John Snow'),
);
expect(nullPick().letOrNull((pick) => Person.fromPick(pick)), isNull);
// allow lambda to return null
final String? a = pick('a').letOrNull((pick) => null);
expect(a, isNull);
expect(pick('a').letOrNull((pick) => null), isNull);
expect(
() => pick('a').letOrNull((pick) => Person.fromPick(pick)),
throwsA(
Expand Down

0 comments on commit 0eb077d

Please sign in to comment.