Skip to content

Instantly share code, notes, and snippets.

import cats.syntax.either._
val eitherRightValue: Either[Boolean, Int] = 35.asRight[Boolean]
val eitherLeftValue: Either[Int, Boolean] = 35.asLeft[Boolean]
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
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
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
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)))
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))