Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Tuple2K#swap #2367

Merged
merged 1 commit into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}

}