Skip to main content

F[Option[A]]

Extension Methods for F[Option[A]]

Change Value

innerMap

val foa: F[Option[A]] = ...
foa.innerMap(A => B) // F[Option[B]]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(1.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 1))

foa.innerMap(_ + 999)
.unsafeRunSync()
// res1: Option[Int] = Some(value = 1000)

innerFlatMap

val foa: F[Option[A]] = ...
foa.innerFlatMap(A => Option[B]) // F[Option[B]]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(1.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 1))

foa.innerFlatMap(a => (a + 999).some)
.unsafeRunSync()
// res3: Option[Int] = Some(value = 1000)

innerFlatMapF

val foa: F[Option[A]] = ...
foa.innerFlatMapF(A => F[Option[B]]) // F[Option[B]]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(1.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 1))

foa.innerFlatMapF(a => IO.pure((a + 999).some))
.unsafeRunSync()
// res5: Option[Int] = Some(value = 1000)

Get Value

innerGetOrElse

val foa: F[Option[A]] = ...
foa.innerGetOrElse[B >: A](=> B) // F[Option[B]]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(999.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 999))
foa.innerGetOrElse(0)
.unsafeRunSync()
// res7: Int = 999

val foa2 = IO.pure(none[Int])
// foa2: IO[Option[Int]] = Pure(a = None)
foa2.innerGetOrElse(0)
.unsafeRunSync()
// res8: Int = 0

innerGetOrElseF

val foa: F[Option[A]] = ...
foa.innerGetOrElseF[B >: A](=> F[B]) // F[Option[B]]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(999.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 999))
foa.innerGetOrElseF(IO.pure(0))
.unsafeRunSync()
// res10: Int = 999

val foa2 = IO.pure(none[Int])
// foa2: IO[Option[Int]] = Pure(a = None)
foa2.innerGetOrElseF(IO.pure(0))
.unsafeRunSync()
// res11: Int = 0

innerFold

val foa: F[Option[A]] = ...
foa.innerFold[B](=> B)(A => B) // F[B]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(1.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 1))
foa.innerFold(0)(_ + 999)
.unsafeRunSync()
// res13: Int = 1000

val foa2 = IO.pure(none[Int])
// foa2: IO[Option[Int]] = Pure(a = None)
foa2.innerFold(0)(_ + 999)
.unsafeRunSync()
// res14: Int = 0

innerFoldF

val foa: F[Option[A]] = ...
foa.innerFoldF[B >: A](=> F[B])(A => F[B]) // F[B]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(1.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 1))

foa.innerFoldF(IO.pure(0))(a => IO.pure(a + 999))
.unsafeRunSync()
// res16: Int = 1000

val foa2 = IO.pure(none[Int])
// foa2: IO[Option[Int]] = Pure(a = None)

foa2.innerFoldF(IO.pure(0))(a => IO.pure(a + 999))
.unsafeRunSync()
// res17: Int = 0

innerOrElse

val foa: F[Option[A]] = ...
foa.innerOrElse[B >: A](Option[B]) // F[Option[B]]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(1.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 1))

foa.innerOrElse(0.some)
.unsafeRunSync()
// res19: Option[Int] = Some(value = 1)

val foa2 = IO.pure(none[Int])
// foa2: IO[Option[Int]] = Pure(a = None)

foa2.innerOrElse(0.some)
.unsafeRunSync()
// res20: Option[Int] = Some(value = 0)

innerOrElseF

val foa: F[Option[A]] = ...
foa.innerOrElse[B >: A](F[Option[B]]) // F[Option[B]]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(1.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 1))

foa.innerOrElseF(IO.pure(0.some))
.unsafeRunSync()
// res22: Option[Int] = Some(value = 1)

val foa2 = IO.pure(none[Int])
// foa2: IO[Option[Int]] = Pure(a = None)

foa2.innerOrElseF(IO.pure(0.some))
.unsafeRunSync()
// res23: Option[Int] = Some(value = 0)

Do

innerForeach

val foa: F[Option[A]] = ...
foa.innerForeach(A => Unit) // F[Unit]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(1.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 1))
foa.innerForeach(println)
.unsafeRunSync()
// 1

val foa2 = IO.pure(none[Int])
// foa2: IO[Option[Int]] = Pure(a = None)
foa2.innerForeach(println)
.unsafeRunSync()

innerForeachF

val foa: F[Option[A]] = ...
foa.innerForeachF(A => F[Unit]) // F[Unit]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(1.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 1))

foa.innerForeachF(a => IO.delay(println(a)))
.unsafeRunSync()
// 1

val foa2 = IO.pure(none[Int])
// foa2: IO[Option[Int]] = Pure(a = None)

foa2.innerForeachF(a => IO.delay(println(a)))
.unsafeRunSync()

innerFilter

val foa: F[Option[A]] = ...
foa.innerFilter(A => Boolean) // F[Option[A]]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(1.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 1))

foa.innerFilter(_ > 0)
.unsafeRunSync()
// res31: Option[Int] = Some(value = 1)

foa.innerFilter(_ > 1)
.unsafeRunSync()
// res32: Option[Int] = None

innerExists

val foa: F[Option[A]] = ...
foa.innerExists(A => Boolean) // F[Boolean]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(1.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 1))

foa.innerExists(_ > 0)
.unsafeRunSync()
// res34: Boolean = true

foa.innerExists(_ > 1)
.unsafeRunSync()
// res35: Boolean = false

innerContains

val foa: F[Option[A]] = ...
foa.innerContains(A) // F[Boolean]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(1.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 1))

foa.innerContains(1)
.unsafeRunSync()
// res37: Boolean = true

foa.innerContains(0)
.unsafeRunSync()
// res38: Boolean = false

innerForall

val foa: F[Option[A]] = ...
foa.innerForall(A) // F[Boolean]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(1.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 1))

foa.innerForall(_ > 0)
.unsafeRunSync()
// res40: Boolean = true

foa.innerForall(_ > 1)
.unsafeRunSync()
// res41: Boolean = false

val foa2 = IO.pure(none[Int])
// foa2: IO[Option[Int]] = Pure(a = None)

foa2.innerForall(_ > 1)
.unsafeRunSync()
// res42: Boolean = true

innerCollect

val foa: F[Option[A]] = ...
foa.innerCollect(PartialFunction[A, B]) // F[Option[B]]

Example

import cats.syntax.all._
import cats.effect._

import extras.cats.syntax.all._

val foa = IO.pure(1.some)
// foa: IO[Option[Int]] = Pure(a = Some(value = 1))

foa.innerCollect {
case 1 => 0
case 2 => 999
}
.unsafeRunSync()
// res44: Option[Int] = Some(value = 0)

val foa2 = IO.pure(2.some)
// foa2: IO[Option[Int]] = Pure(a = Some(value = 2))

foa2.innerCollect {
case 1 => 0
case 2 => 999
}
.unsafeRunSync()
// res45: Option[Int] = Some(value = 999)

val foa3 = IO.pure(3.some)
// foa3: IO[Option[Int]] = Pure(a = Some(value = 3))

foa3.innerCollect {
case 1 => 0
case 2 => 999
}
.unsafeRunSync()
// res46: Option[Int] = None