option<T, Input> static method

BcsType<T?, Input?> option<T, Input>(
  1. BcsType<T, Input> type
)

Implementation

static BcsType<T?, Input?> option<T, Input>(BcsType<T, Input> type) {
  return enumeration('Option<${type.name}>', {
    'None': null,
    'Some': type,
  }).transform(
    input: (Input? value) {
      if (value == null) {
        return {'None': true};
      }
      return {'Some': value};
    },
    output: (value) {
      if (value.containsKey('Some')) {
        return value['Some'] as T;
      }
      return null;
    },
  );
}