Maybe

sealed abstract
class Maybe[A]

An optional value

A Maybe[A] will either be a wrapped A instance (Just[A]), or a lack of underlying A instance (Empty[A]).

Maybe[A] is isomorphic to Option[A], however there are some differences between the two. Maybe is invariant in A while Option is covariant. Maybe[A] does not expose an unsafe get operation to access the underlying A value (that may not exist) like Option[A] does. Maybe[A] does not come with an implicit conversion to Iterable[A] (a trait with over a dozen super types).

Companion
object
class Object
trait Matchable
class Any
class Empty[A]
class Just[A]

Value members

Concrete methods

final
def <\/[B](b: => B): A \/ B

alias for toLeft

alias for toLeft

final
def \/>[B](b: => B): B \/ A

alias for toRight

alias for toRight

final
def cata[B](f: A => B, b: => B): B

Catamorphism. Run the given function on the underlying value if present, otherwise return the provided fallback value

Catamorphism. Run the given function on the underlying value if present, otherwise return the provided fallback value

final
def cobind[B](f: Maybe[A] => B): Maybe[B]
final
def cojoin: Maybe[Maybe[A]]
final
def exists(f: A => Boolean): Boolean

Return true if this is a Maybe.Just and the underlying value satisfies the provided predicate

Return true if this is a Maybe.Just and the underlying value satisfies the provided predicate

final
def filter(f: A => Boolean): Maybe[A]
final
def filterNot(f: A => Boolean): Maybe[A]
final

Tag with Tags.First

Tag with Tags.First

final
def flatMap[B](f: A => Maybe[B]): Maybe[B]
final
def forall(f: A => Boolean): Boolean

Return true if this is a Maybe.Empty or if this is a Maybe.Just and the underlying value satisfies the provided predicate

Return true if this is a Maybe.Empty or if this is a Maybe.Just and the underlying value satisfies the provided predicate

final
def getOrElse(a: => A): A

Return the underlying value if present, otherwise the provided fallback value

Return the underlying value if present, otherwise the provided fallback value

final
def getOrElseF[F[_] : Applicative](fa: => F[A]): F[A]
final
def isEmpty: Boolean

True if no underlying value is present

True if no underlying value is present

final
def isJust: Boolean

True if an underlying value is present

True if an underlying value is present

final
def last: LastMaybe[A]

Tag with Tags.Last

Tag with Tags.Last

final
def map[B](f: A => B): Maybe[B]
final
def max: MaxMaybe[A]

Tag with Tags.Max

Tag with Tags.Max

final
def min: MinMaybe[A]

Tag with Tags.Min

Tag with Tags.Min

final
def orElse(oa: => Maybe[A]): Maybe[A]

Return this instance if it is a Maybe.Just, otherwise the provided fallback

Return this instance if it is a Maybe.Just, otherwise the provided fallback

final
def orEmpty[F[_]](implicit F: ApplicativePlus[F]): F[A]

Return the underlying value wrapped in type F if present, otherwise the empty value for type F

Return the underlying value wrapped in type F if present, otherwise the empty value for type F

final
def orError[F[_], E](e: E)(implicit F: MonadError[F, E]): F[A]
final
def orZero(implicit F: Monoid[A]): A

Return the underlying value if present, otherwise the monoid zero

Return the underlying value if present, otherwise the monoid zero

final
def toFailure[B](b: => B): Validation[A, B]

Turn the underlying value into a failure validation if present, otherwise return a success validation with the provided fallback value

Turn the underlying value into a failure validation if present, otherwise return a success validation with the provided fallback value

final
def toLeft[B](b: => B): A \/ B

Turn the underlying value into a left disjunction if present, otherwise return a right disjunction with the provided fallback value

Turn the underlying value into a left disjunction if present, otherwise return a right disjunction with the provided fallback value

final
def toOption: Option[A]

Convert to a standard library Option

Convert to a standard library Option

final
def toRight[B](b: => B): B \/ A

Turn the underlying value into a right disjunction if present, otherwise return a left disjunction with the provided fallback value

Turn the underlying value into a right disjunction if present, otherwise return a left disjunction with the provided fallback value

final
def toSuccess[B](b: => B): Validation[B, A]

Turn the underlying value into a success validation if present, otherwise return a failure validation with the provided fallback value

Turn the underlying value into a success validation if present, otherwise return a failure validation with the provided fallback value

final
def unary_~(implicit z: Monoid[A]): A

alias for orZero

alias for orZero

final
def zip[B](fb: Maybe[B]): Maybe[(A, B)]
final
def zipWith[B, C](fb: Maybe[B])(f: (A, B) => C): Maybe[C]
final
def |(a: => A): A

alias for getOrElse

alias for getOrElse