Skip to content

ValidatedNelOps<E, A>

extension ValidatedNelOps<E, A> on ValidatedNel<NonEmptyIList<E>, A>

Functions that are unique to a Validated that has a NonEmptyIList<E> for the invalid type.

Methods

ap() extension

ValidatedNel<NonEmptyIList<E>, B> ap<B>(
  ValidatedNel<NonEmptyIList<E>, B Function(A)> f,
)

Applies f to this value if both instance are Valid. Otherwise returns the error if either is Invalid or the accumulation of errors if both are Invalid.

Available on Validated<E, A>, provided by the ValidatedNelOps<E, A> extension

Implementation
dart
ValidatedNel<E, B> ap<B>(ValidatedNel<E, Function1<A, B>> f) {
  return fold(
    (e) => f.fold(
      (ef) => e.concatNel(ef).invalid(),
      (af) => e.invalid(),
    ),
    (a) => f.fold(
      (ef) => ef.invalid(),
      (af) => af(a).validNel<E>(),
    ),
  );
}

product() extension

ValidatedNel<NonEmptyIList<E>, Record> product<B>(
  ValidatedNel<NonEmptyIList<E>, B> that,
)

Returns the product (tuple) of this validation and that if both instances are Valid. Otherwise returns the error if either is Invalid or the accumulation of errors if both are Invalid.

Available on Validated<E, A>, provided by the ValidatedNelOps<E, A> extension

Implementation
dart
ValidatedNel<E, (A, B)> product<B>(ValidatedNel<E, B> that) {
  return fold(
    (e) => that.fold(
      (ef) => e.concatNel(ef).invalid(),
      (af) => e.invalid(),
    ),
    (a) => that.fold(
      (ef) => ef.invalid(),
      (af) => (a, af).validNel<E>(),
    ),
  );
}