raise method

  1. @monadComprehensions
Never raise(
  1. L value
)

Short-circuits the Either.binding or Either.bindingAsync scope that owns this effect with value as its Left.

This is convenience syntax for the case where the caller already has a left value and would otherwise construct a Left solely to call BindEitherEffectExtension.bind. For example, effect.raise('error') has the same short-circuit result as effect.bind(Either<String, Never>.left('error')) without creating the intermediate Left. Its Never return type allows use in expressions.

See Either.binding and Either.bindingAsync.

Example

final result = Either<String, int>.binding((effect) {
  final int? value = null;
  return value ?? effect.raise('missing value');
}); // Left('missing value')

Implementation

@monadComprehensions
Never raise(L value) => _raise(value);