From fea22073a7a6dab59f0d09349df04779d3f0db6c Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Mon, 29 Jul 2024 14:56:14 -0400 Subject: [PATCH 1/2] add some ResultT constructors --- modules/core/src/main/scala/result.scala | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/modules/core/src/main/scala/result.scala b/modules/core/src/main/scala/result.scala index e3729a89..898c723a 100644 --- a/modules/core/src/main/scala/result.scala +++ b/modules/core/src/main/scala/result.scala @@ -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]) + } From 5641cb9754f524f53850b88a01a5ce80ed551f3d Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Tue, 30 Jul 2024 11:38:32 -0400 Subject: [PATCH 2/2] moar --- modules/core/src/main/scala/result.scala | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/core/src/main/scala/result.scala b/modules/core/src/main/scala/result.scala index 898c723a..9c07414b 100644 --- a/modules/core/src/main/scala/result.scala +++ b/modules/core/src/main/scala/result.scala @@ -418,6 +418,15 @@ 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])