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

io.magentys.donut.package.scala Maven / Gradle / Ivy

The newest version!
package io.magentys

import scala.util.{Failure, Success, Try}

package object donut {
  implicit class TryExtension[A](t: Try[A]) {
    def toEither[E](f: Throwable => E): Either[E, A] = {
      t match {
        case Success(s) => Right(s)
        case Failure(e) => Left(f(e))
      }
    }
  }

  def sequenceEither[E, R](s: List[Either[E, R]]): Either[List[E], List[R]] = {
    val errors = s.filter(_.isLeft).map(e => e.left.get)
    if (errors.nonEmpty) Left(errors) else Right(s.map(e => e.right.get))
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy