flatMap<O> method

ValidatorT<S, O> flatMap<O>(
  1. ValidatorT<T, O> process(
    1. T
    )
)

Recieves a function that generates a validator and plumbs the output of the current to validator to the function.

Implementation

ValidatorT<S, O> flatMap<O>(ValidatorT<T, O> Function(T) process) {
  return (S input) {
    final lhsOutput = this(input);

    final Either<List<dynamic>, O> result = lhsOutput.fold(
      (err) => Left(err),
      (T value) {
        final ValidatorT<T, O> producedValidator = process(value);
        final result = producedValidator(value);
        return result;
      },
    );

    return result;
  };
}