Last active
December 10, 2019 03:35
-
-
Save justinhj/756b5290ec679a2a02b9310b800b9313 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.Semigroup | |
import cats.implicits._ | |
// Combining strings | |
"Semigroups".combine(" ".combine("combine".combine(" ".combine("things")))) | |
// res1: String = "Semigroups combine things | |
// Which is hard to read so Cats provides convenient infix syntax | |
"Semigroups" |+| " " |+| "combine" |+| " " |+| "things" | |
// res2: String = "Semigroups combine things" | |
// Combining Integers | |
10 |+| 20 | |
// res3: Int = 30 | |
// Combining Tuples of Semigroups | |
(1, "two") |+| (3, "four") | |
// res4: (Int, String) = (4, "twofour") | |
// Combining Futures of Either[String,Int] | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.Future | |
Future(10.asRight[String]) |+| Future(20.asRight[String]) | |
// res5: Future[Either[String, Int]] = Future(Success(Right(30))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment