map<U> method

ResultOf<U?> map<U>([
  1. U valueConverter(
    1. T
    )?
])
Convert result with value to result with another value. Use valueConverter parameter to specify the value transformation logic.

No need valueConverter for Fail result. But for Success you should define it.

Implementation

ResultOf<U?> map<U>([U Function(T)? valueConverter]) {
  if (isSuccess) {
    if (valueConverter == null) {
      throw Exception(
        'If result is success then valueConverter should not be null',
      );
    }
    return ResultOf.success<U>(valueConverter(value as T));
  }

  return fail(error);
}