foldLeft<C> method

C foldLeft<C>(
  1. C initial,
  2. C rightOperation(
    1. C acc,
    2. R element
    )
)

If this is a Right, applies ifRight with initial and Right.value. Returns initial otherwise.

Example

final Either<Exception, String> result = Either.right('hoc081098');
final String initial = 'dart_either';
String combine(String acc, String v) => '$acc $v';

result.foldLeft<String>(initial, combine); // Result: 'dart_either hoc081098'

Implementation

C foldLeft<C>(C initial, C Function(C acc, R element) rightOperation) =>
    _foldInternal(
      ifLeft: _const(initial),
      ifRight: (r) => rightOperation(initial, r),
    );