map<A, B> method

  1. @override
Result<A, B> map<A, B>({
  1. A ok(
    1. O ok
    )?,
  2. B err(
    1. E err
    )?,
})
override

Take the current Result and transform it's values to a new Result.

Example:

  final result = ok<String, Exception>('hi');

  Result<int, Error> newResult = result.map(
    ok: (ok) => 1,
    err: (err) => Error(),
  );

Implementation

@override
Result<A, B> map<A, B>({A Function(O ok)? ok, B Function(E err)? err}) {
  if (err != null) {
    return Err(err(val));
  } else {
    return Err(val as B);
  }
}