From d0193b27b96ee204a843e82f115b3711a14bb19e Mon Sep 17 00:00:00 2001 From: geirolz Date: Mon, 9 Oct 2023 12:31:05 +0200 Subject: [PATCH 1/2] Add asRightIn, asLeftIn and asSomeIn for anyF --- shared/src/main/scala/mouse/anyf.scala | 9 +++++++++ shared/src/test/scala/mouse/AnyFSyntaxTest.scala | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/shared/src/main/scala/mouse/anyf.scala b/shared/src/main/scala/mouse/anyf.scala index a6e52734..53ac3c53 100644 --- a/shared/src/main/scala/mouse/anyf.scala +++ b/shared/src/main/scala/mouse/anyf.scala @@ -34,6 +34,15 @@ final class AnyFOps[F[_], A](private val fa: F[A]) extends AnyVal { @inline def ||>[G[_]](f: F ~> G): G[A] = f(fa) @inline def thrushK[G[_]](f: F ~> G): G[A] = f(fa) + def asRightIn[L](implicit F: Functor[F]): F[Either[L, A]] = + Functor[F].map(fa)(Right(_)) + + def asLeftIn[R](implicit F: Functor[F]): F[Either[A, R]] = + Functor[F].map(fa)(Left(_)) + + def asSomeIn(implicit F: Functor[F]): F[Option[A]] = + Functor[F].map(fa)(Some(_)) + def liftEitherT[E](implicit F: Functor[F]): EitherT[F, E, A] = EitherT.right[E](fa) diff --git a/shared/src/test/scala/mouse/AnyFSyntaxTest.scala b/shared/src/test/scala/mouse/AnyFSyntaxTest.scala index 9db0a7be..46add3e8 100644 --- a/shared/src/test/scala/mouse/AnyFSyntaxTest.scala +++ b/shared/src/test/scala/mouse/AnyFSyntaxTest.scala @@ -63,6 +63,18 @@ class AnyFSyntaxTest extends MouseSuite { ) } + test("AnyFSyntax.asRightIn") { + assertEquals(List(1).asRightIn[String], List(1.asRight)) + } + + test("AnyFSyntax.asLeftIn") { + assertEquals(List(1).asLeftIn[String], List(1.asLeft)) + } + + test("AnyFSyntax.asSomeIn") { + assertEquals(List(1).asSomeIn, List(1.some)) + } + test("AnyFSyntax.liftEitherT") { assertEquals(List(1).liftEitherT[String], EitherT(List(1.asRight[String]))) } From 6b3d2a7d053332445bf267fb89529f5c304a1673 Mon Sep 17 00:00:00 2001 From: geirolz Date: Mon, 16 Oct 2023 15:31:46 +0200 Subject: [PATCH 2/2] Rename methods --- shared/src/main/scala/mouse/anyf.scala | 6 +++--- shared/src/test/scala/mouse/AnyFSyntaxTest.scala | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/shared/src/main/scala/mouse/anyf.scala b/shared/src/main/scala/mouse/anyf.scala index 53ac3c53..e9056bfb 100644 --- a/shared/src/main/scala/mouse/anyf.scala +++ b/shared/src/main/scala/mouse/anyf.scala @@ -34,13 +34,13 @@ final class AnyFOps[F[_], A](private val fa: F[A]) extends AnyVal { @inline def ||>[G[_]](f: F ~> G): G[A] = f(fa) @inline def thrushK[G[_]](f: F ~> G): G[A] = f(fa) - def asRightIn[L](implicit F: Functor[F]): F[Either[L, A]] = + def mapAsRight[L](implicit F: Functor[F]): F[Either[L, A]] = Functor[F].map(fa)(Right(_)) - def asLeftIn[R](implicit F: Functor[F]): F[Either[A, R]] = + def mapAsLeft[R](implicit F: Functor[F]): F[Either[A, R]] = Functor[F].map(fa)(Left(_)) - def asSomeIn(implicit F: Functor[F]): F[Option[A]] = + def mapAsSome(implicit F: Functor[F]): F[Option[A]] = Functor[F].map(fa)(Some(_)) def liftEitherT[E](implicit F: Functor[F]): EitherT[F, E, A] = diff --git a/shared/src/test/scala/mouse/AnyFSyntaxTest.scala b/shared/src/test/scala/mouse/AnyFSyntaxTest.scala index 46add3e8..5e871474 100644 --- a/shared/src/test/scala/mouse/AnyFSyntaxTest.scala +++ b/shared/src/test/scala/mouse/AnyFSyntaxTest.scala @@ -64,15 +64,15 @@ class AnyFSyntaxTest extends MouseSuite { } test("AnyFSyntax.asRightIn") { - assertEquals(List(1).asRightIn[String], List(1.asRight)) + assertEquals(List(1).mapAsRight[String], List(1.asRight)) } test("AnyFSyntax.asLeftIn") { - assertEquals(List(1).asLeftIn[String], List(1.asLeft)) + assertEquals(List(1).mapAsLeft[String], List(1.asLeft)) } test("AnyFSyntax.asSomeIn") { - assertEquals(List(1).asSomeIn, List(1.some)) + assertEquals(List(1).mapAsSome, List(1.some)) } test("AnyFSyntax.liftEitherT") {