asMapOrEmpty<RK, RV> method
Returns the picked value as Map or an empty map when the value
isn't a Map or isAbsent.
Provides a view of this map as having RK
keys and RV
instances,
if necessary.
If this map is already a Map<RK, RV>
, it is returned unchanged.
If any operation exposes a non-RK
key or non-RV
value,
the operation will throw instead.
If any operation exposes a duplicate RK
key RV
value is replaced
with new one,
Entries added to the map must be valid for both a Map<K, V>
and a
Map<RK, RV>
.
via Map cast function
final map = pick({
'a': 'John Snow',
'b': 1,
'c': null,
'a': 'John Snow updated',
}).asMapOrThrow()
// map
{
'a': 'John Snow updated',
'b': 1,
'c': null,
}
Implementation
Map<RK, RV> asMapOrEmpty<RK, RV>() {
if (value == null) return <RK, RV>{};
if (value is! Map) return <RK, RV>{};
return _parse();
}