map<K, V, InputK, InputV> static method

BcsType<Map<K, V>, Map<InputK, InputV>> map<K, V, InputK, InputV>(
  1. BcsType<K, InputK> keyType,
  2. BcsType<V, InputV> valueType
)

Implementation

static BcsType<Map<K, V>, Map<InputK, InputV>> map<K, V, InputK, InputV>(
  BcsType<K, InputK> keyType,
  BcsType<V, InputV> valueType
) {
  return Bcs.vector(Bcs.tuple([keyType, valueType])).transform(
    name: 'Map<${keyType.name}, ${valueType.name}>',
    input: (Map<InputK, InputV> value) {
      return value.entries.map((e) => [e.key, e.value]).toList();
    },
    output: (List<List> value) {
      return Map.fromEntries(
        value.map((e) => MapEntry(e[0] as K, e[1] as V))
      );
    },
  );
}