Skip to content

Commit

Permalink
add some ResultT constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
tpolecat committed Jul 29, 2024
1 parent 84f304b commit fea2207
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 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,35 @@ object ResultT {
}
)
}

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

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 fea2207

Please sign in to comment.