letOrNull<R> method
Maps the pick if value != null and returns the result.
This methods allows mapping of optional values in a single line
Example:
// with letOrNull
User? user = pick(json, 'users', 0).letOrNull((pick) => User.fromJson(pick.asMap()));
// traditionally
Pick pick = pick(json, 'users', 0);
User? user;
if (pick.value != null) {
user = User.fromJson(pick.asMap());
}
Implementation
R? letOrNull<R>(R Function(RequiredPick pick) block) {
if (value == null) return null;
return block(required());
}