Skip to content

Commit

Permalink
Merge pull request #644 from typelevel/ResultT-ctors
Browse files Browse the repository at this point in the history
add some ResultT constructors
  • Loading branch information
milessabin committed Jul 31, 2024
2 parents 84f304b + 5641cb9 commit 6cdd5fc
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions modules/core/src/main/scala/result.scala
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,44 @@ object ResultT {
}
)
}

def liftF[F[_]: Functor, A](fa: F[A]): ResultT[F, A] =
ResultT(fa.map(Result.success))

def unit[F[_]](implicit F: Applicative[F]): ResultT[F, Unit] =
pure(())

def pure[F[_], A](a: A)(implicit F: Applicative[F]): ResultT[F, A] =
fromResult(Result.pure(a))

def fromResult[F[_], A](a: Result[A])(implicit F: Applicative[F]): ResultT[F, A] =
ResultT(a.pure[F])

def success[F[_]: Applicative, A](a: A): ResultT[F, A] =
ResultT(Result.success(a).pure[F])

def warning[F[_]: Applicative, A](warning: NonEmptyChain[Problem], value: A): ResultT[F, A] =
ResultT(Result.Warning(warning, value).pure[F].widen)

def warning[F[_]: Applicative, A](warning: Problem, value: A): ResultT[F, A] =
ResultT(Result.warning(warning, value).pure[F])

def warning[F[_]: Applicative, A](warning: String, value: A): ResultT[F, A] =
ResultT(Result.warning(warning, value).pure[F])

def failure[F[_]: Applicative, A](s: String): ResultT[F, A] =
ResultT(Result.failure[A](s).pure[F])

def failure[F[_]: Applicative, A](p: Problem): ResultT[F, A] =
ResultT(Result.failure[A](p).pure[F])

def failure[F[_]: Applicative, A](ps: NonEmptyChain[Problem]): ResultT[F, A] =
ResultT(Result.Failure(ps).pure[F].widen)

def internalError[F[_]: Applicative, A](err: Throwable): ResultT[F, A] =
ResultT(Result.internalError[A](err).pure[F])

def internalError[F[_]: Applicative, A](err: String): ResultT[F, A] =
ResultT(Result.internalError[A](err).pure[F])

}

0 comments on commit 6cdd5fc

Please sign in to comment.