All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fly4s.data.ValidateResult.scala Maven / Gradle / Ivy

The newest version!
package fly4s.data

import cats.data.{NonEmptyList, ValidatedNel}
import cats.ApplicativeThrow

object ValidateResult {

  import cats.implicits.*

  import scala.jdk.CollectionConverters.CollectionHasAsScala

  def toValidatedNel[F[_]](
    v: ValidateResult
  )(implicit F: ApplicativeThrow[F]): F[ValidatedNel[ValidateOutput, Unit]] =
    if (v.validationSuccessful)
      F.pure(().valid)
    else
      NonEmptyList
        .fromList(v.invalidMigrations.asScala.toList) match {
        case Some(invalidMigrations) => invalidMigrations.invalid[Unit].pure[F]
        case None =>
          F.raiseError(
            new RuntimeException("InvalidMigrations list are empty but must be NON-empty!")
          )
      }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy