fold<T> method

T fold<T>(
  1. T onLeft(
    1. L left
    ),
  2. T onRight(
    1. R right
    )
)

Folds the Either into a single value, applying onLeft if this is Left, and onRight if this is Right.

Implementation

T fold<T>(
  T Function(L left) onLeft,
  T Function(R right) onRight,
) {
  if (this is Left) {
    return onLeft((this as Left<L, R>).value);
  } else {
    return onRight((this as Right<L, R>).value);
  }
}