compactMap<K, V> static method

CustomLayout compactMap<K, V>(
  1. Layout keyLayout,
  2. Layout valueLayout, {
  3. String? property,
})

Implementation

static CustomLayout compactMap<K, V>(Layout keyLayout, Layout valueLayout,
    {String? property}) {
  final layout = struct([
    seq(
        MapEntryLayout(
            keyLayout: keyLayout, valueLayout: valueLayout, property: ""),
        compactOffset(),
        property: 'values')
  ]);
  return CustomLayout<Map<String, dynamic>, Map<K, V>>(
    layout: layout,
    decoder: (data) {
      final List<MapEntry<K, V>> values = (data['values'] as List).cast();
      return Map.fromEntries(values);
    },
    encoder: (values) => {'values': values.entries.toList()},
    property: property,
  );
}