Skip to content

Commit b0da564

Browse files
authored
Add asRightIn, asLeftIn and asSomeIn for anyF (#460)
* Add asRightIn, asLeftIn and asSomeIn for anyF * Rename methods
1 parent 84ebcc6 commit b0da564

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

shared/src/main/scala/mouse/anyf.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ final class AnyFOps[F[_], A](private val fa: F[A]) extends AnyVal {
3434
@inline def ||>[G[_]](f: F ~> G): G[A] = f(fa)
3535
@inline def thrushK[G[_]](f: F ~> G): G[A] = f(fa)
3636

37+
def mapAsRight[L](implicit F: Functor[F]): F[Either[L, A]] =
38+
Functor[F].map(fa)(Right(_))
39+
40+
def mapAsLeft[R](implicit F: Functor[F]): F[Either[A, R]] =
41+
Functor[F].map(fa)(Left(_))
42+
43+
def mapAsSome(implicit F: Functor[F]): F[Option[A]] =
44+
Functor[F].map(fa)(Some(_))
45+
3746
def liftEitherT[E](implicit F: Functor[F]): EitherT[F, E, A] =
3847
EitherT.right[E](fa)
3948

shared/src/test/scala/mouse/AnyFSyntaxTest.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ class AnyFSyntaxTest extends MouseSuite {
6363
)
6464
}
6565

66+
test("AnyFSyntax.asRightIn") {
67+
assertEquals(List(1).mapAsRight[String], List(1.asRight))
68+
}
69+
70+
test("AnyFSyntax.asLeftIn") {
71+
assertEquals(List(1).mapAsLeft[String], List(1.asLeft))
72+
}
73+
74+
test("AnyFSyntax.asSomeIn") {
75+
assertEquals(List(1).mapAsSome, List(1.some))
76+
}
77+
6678
test("AnyFSyntax.liftEitherT") {
6779
assertEquals(List(1).liftEitherT[String], EitherT(List(1.asRight[String])))
6880
}

0 commit comments

Comments
 (0)