fly4s.data.ValidateResult.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fly4s_3 Show documentation
Show all versions of fly4s_3 Show documentation
A functional wrapper for Flywayy
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!")
)
}
}