fold<C> method

C fold<C>({
  1. required C ifLeft(
    1. L value
    ),
  2. required C ifRight(
    1. R value
    ),
})

Applies ifLeft if this is a Left or ifRight if this is a Right.

ifLeft is the function to apply if this is a Left. ifRight is the function to apply if this is a Right.

Returns the results of applying the function.

Example

final Either<Exception, String> result = Either.right('hoc081098');

// Prints operation succeeded with hoc081098
result.fold(
  ifLeft: (value) => print('operation failed with $value') ,
  ifRight: (value) => print('operation succeeded with $value'),
);

Implementation

C fold<C>({
  required C Function(L value) ifLeft,
  required C Function(R value) ifRight,
}) =>
    _foldInternal(ifLeft: ifLeft, ifRight: ifRight);