Skip to content

Commit

Permalink
add Tuple2K#swap (typelevel#2367)
Browse files Browse the repository at this point in the history
  • Loading branch information
aoiroaoino authored and catostrophe committed Sep 15, 2018
1 parent 9a59eb6 commit d49ea71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/src/main/scala/cats/data/Tuple2K.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final case class Tuple2K[F[_], G[_], A](first: F[A], second: G[A]) {
def mapK[H[_]](f: G ~> H): Tuple2K[F, H, A] =
Tuple2K(first, f(second))

def swap: Tuple2K[G, F, A] = Tuple2K(second, first)
}

object Tuple2K extends Tuple2KInstances
Expand Down
8 changes: 8 additions & 0 deletions tests/src/test/scala/cats/tests/Tuple2KSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,12 @@ class Tuple2KSuite extends CatsSuite {
}
}

test("double swap is identity") {
forAll { (l1: Option[String], l2: List[String]) =>
val tuple = Tuple2K(l1, l2)

tuple.swap.swap should === (tuple)
}
}

}

0 comments on commit d49ea71

Please sign in to comment.