bimap<C, D> method
Either<C, D>
bimap<C, D>({
- required C leftOperation(
- L value
- required D rightOperation(
- R value
Map over Left and Right of this Either
Example
final Either<String, int> either = Right(1);
// Result: Right('1')
final Either<List<String>, String> mapped = either.bimap(
leftOperation: (String s) => s.split(''),
rightOperation: (int i) => i.toString(),
);
final Either<String, int> either = Left('hoc081098');
// Result: Left(['h', 'o', 'c', '0', '8', '1', '0', '9', '8'])
final Either<List<String>, String> mapped = either.bimap(
leftOperation: (String s) => s.split(''),
rightOperation: (int i) => i.toString(),
);
Implementation
Either<C, D> bimap<C, D>({
required C Function(L value) leftOperation,
required D Function(R value) rightOperation,
}) =>
_foldInternal(
ifLeft: (l) => Either.left(leftOperation(l)),
ifRight: (r) => Either.right(rightOperation(r)),
);