asMapOrThrow<RK, RV> method

Map<RK, RV> asMapOrThrow<RK, RV>()

Returns the picked value as Map. This method throws when value is not 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> asMapOrThrow<RK, RV>() {
  withContext(
    requiredPickErrorHintKey,
    'Use asMapOrEmpty()/asMapOrNull() when the value may be null/absent at some point (Map<$RK, $RV>?).',
  );
  return _parse();
}