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.syntax.either._ | |
val eitherRightValue: Either[Boolean, Int] = 35.asRight[Boolean] | |
val eitherLeftValue: Either[Int, Boolean] = 35.asLeft[Boolean] |
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.instances.future._ | |
import cats.syntax.cartesian._ | |
val addFutureValue = Future(2 + 1) | |
val multiplyFutureValue = Future(2 * 1) | |
val substractFutureValue = Future(2 - 1) | |
val result: Future[Int] = (addFutureValue |@| multiplyFutureValue |@| substractFutureValue).map{ (addedValue, multipiedValue, substractedValue) => | |
addedValue + multipiedValue + substractedValue |
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.data.OptionT | |
val futureValue: Future[Option[Int]] = Future(Option(23)) | |
val optionTValue: OptionT[Future, Int] = OptionT(futureValue) | |
val extractedFutureValue: Future[Option[Int]] = optionTValue.value |
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.data.EitherT | |
import cats.syntax.either._ | |
val eitherValue: Either[Boolean, Int] = 35.asRight[Boolean] | |
val futureEitherValue: Future[Either[Boolean, Int]] = Future(eitherValue) | |
val eitherTValue: EitherT[Future, Boolean, Int] = EitherT(futureEitherValue) | |
val extractedFutureValue: Future[Either[Boolean, Int]] = eitherTValue.value |
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.implicits._ | |
val listValue: List[Option[Int]] = List(35.some, 45.some, 55.some)) | |
val result: Option[List[Int]] = listValue.flatTraverse(_.map(x=>List(x))) |
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.syntax.traverse._ | |
import cats.instances.future._ | |
import cats.syntax.option._ | |
import cats.instances.option._ | |
val optionalValue: Option[Int] = 35.some | |
val finalResult: Future[Option[Int]] = optionalValue.traverse(value => Future(value + 1)) |
OlderNewer