Skip to content

Commit 3ff178e

Browse files
[#70] RightBiasedEither.rightMap does not work with Left
Changes: - add test about rightMap - fix cast, instead of casting the implicit class, we cast the target of the implicit conversion
1 parent a2f7870 commit 3ff178e

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

common/src/main/scala/it/agilelab/darwin/common/compat/package.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ package object compat {
5858
}
5959
}
6060

61-
implicit class RightBiasedEither[+L, +R](self: Either[L, R]) {
61+
implicit class RightBiasedEither[+L, +R](val self: Either[L, R]) extends AnyVal {
6262
def rightMap[R1](f: R => R1): Either[L, R1] = {
6363
self match {
6464
case Right(v) => Right(f(v))
65-
case _ => this.asInstanceOf[Either[L, R1]]
65+
case _ => self.asInstanceOf[Either[L, R1]]
6666
}
6767
}
6868
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package it.agilelab.darwin.common
2+
3+
import org.scalatest.flatspec.AnyFlatSpec
4+
import org.scalatest.matchers.should.Matchers
5+
import compat._
6+
7+
class CompatSpec extends AnyFlatSpec with Matchers {
8+
9+
"RightBiasedEither" should "map correctly on left side" in {
10+
Left[Int, String](3).rightMap {
11+
"Hello" + _
12+
} shouldBe Left[Int, String](3)
13+
}
14+
15+
it should "map correctly on right side" in {
16+
Right[Int, String]("Darwin").rightMap {
17+
"Hello " + _
18+
} shouldBe Right[Int, String]("Hello Darwin")
19+
}
20+
}

0 commit comments

Comments
 (0)