Maybe

kyo.Maybe$package.Maybe
opaque object Maybe

Companion object for Maybe type

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Maybe.type

Members list

Type members

Classlikes

object Defined

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Defined.type
sealed abstract class Empty

Represents an empty Maybe instance.

Represents an empty Maybe instance.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Empty
case object Empty extends Empty

Attributes

Companion
class
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
class Empty
class Object
trait Matchable
class Any
Show all
Self type
Empty.type
final implicit class Ops[A](maybe: Maybe[A]) extends AnyVal

Provides operations on Maybe instances.

Provides operations on Maybe instances.

Attributes

Supertypes
class AnyVal
trait Matchable
class Any

Types

opaque type Defined[+A]

Represents a defined value in a Maybe.

Represents a defined value in a Maybe.

Attributes

Value members

Concrete methods

def apply[A](v: A): Maybe[A]

Creates a Maybe instance from a value.

Creates a Maybe instance from a value.

Type parameters

A

the type of the value

Value parameters

v

the value to wrap

Attributes

Returns

a Maybe instance containing the value, or Empty if the value is null

def empty[A]: Maybe[A]

Creates an empty Maybe instance.

Creates an empty Maybe instance.

Type parameters

A

the type parameter of the Maybe

Attributes

Returns

an Empty instance

def fromOption[A](opt: Option[A]): Maybe[A]

Converts an Option to a Maybe.

Converts an Option to a Maybe.

Type parameters

A

the type of the value

Value parameters

opt

the Option to convert

Attributes

Returns

a Maybe instance equivalent to the input Option

inline def when[A](cond: Boolean)(inline v: => A): Maybe[A]

Creates a Maybe instance based on a condition.

Creates a Maybe instance based on a condition.

Type parameters

A

the type of the value

Value parameters

cond

the condition to evaluate

v

the value to wrap if the condition is true

Attributes

Returns

a Maybe instance containing the value if the condition is true, or Empty otherwise

Givens

Givens

inline given given_CanEqual_Maybe_Maybe[A, B](using inline ce: CanEqual[A, B]): CanEqual[Maybe[A], Maybe[B]]
given given_Conversion_Maybe_IterableOnce[A]: Conversion[Maybe[A], IterableOnce[A]]

Extensions

Extensions

extension [A](self: Maybe[A])
inline def collect[B](pf: PartialFunction[A, B]): Maybe[B]

Applies a partial function to the contained value if defined.

Applies a partial function to the contained value if defined.

Type parameters

B

the return type of the partial function

Value parameters

pf

the partial function to apply

Attributes

Returns

a new Maybe containing the result of the partial function if defined and applicable, or Empty otherwise

def contains[B](elem: B)(using CanEqual[A, B]): Boolean

Checks if the Maybe contains a specific value.

Checks if the Maybe contains a specific value.

Type parameters

B

the type of the element to check

Value parameters

elem

the value to check for

ev

evidence of equality between A and B

Attributes

Returns

true if the Maybe is defined and contains the specified value, false otherwise

inline def exists(inline f: A => Boolean): Boolean

Checks if the Maybe satisfies a predicate.

Checks if the Maybe satisfies a predicate.

Value parameters

f

the predicate function

Attributes

Returns

true if the Maybe is defined and satisfies the predicate, false otherwise

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

Filters the Maybe based on a predicate.

Filters the Maybe based on a predicate.

Value parameters

f

the predicate function

Attributes

Returns

the Maybe if it's defined and satisfies the predicate, or Empty otherwise

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

Filters the Maybe based on a negated predicate.

Filters the Maybe based on a negated predicate.

Value parameters

f

the predicate function to negate

Attributes

Returns

the Maybe if it's defined and doesn't satisfy the predicate, or Empty otherwise

inline def flatMap[B](inline f: A => Maybe[B]): Maybe[B]

Applies a function that returns a Maybe to the contained value if defined.

Applies a function that returns a Maybe to the contained value if defined.

Type parameters

B

the type parameter of the resulting Maybe

Value parameters

f

the function to apply

Attributes

Returns

the result of applying the function if defined, or Empty if empty

inline def flatten[B](using inline ev: A <:< Maybe[B]): Maybe[B]

Flattens a Maybe of Maybe into a single Maybe.

Flattens a Maybe of Maybe into a single Maybe.

Type parameters

B

the type parameter of the inner Maybe

Value parameters

ev

evidence that A is a subtype of Maybe[B]

Attributes

Returns

the flattened Maybe

inline def fold[B](inline ifEmpty: => B)(inline ifDefined: A => B): B

Applies one of two functions depending on whether the Maybe is empty or defined.

Applies one of two functions depending on whether the Maybe is empty or defined.

Type parameters

B

the return type of both functions

Value parameters

ifDefined

the function to apply if defined

ifEmpty

the function to apply if empty

Attributes

Returns

the result of applying the appropriate function

inline def forall(inline f: A => Boolean): Boolean

Checks if the Maybe satisfies a predicate or is empty.

Checks if the Maybe satisfies a predicate or is empty.

Value parameters

f

the predicate function

Attributes

Returns

true if the Maybe is empty or satisfies the predicate, false otherwise

inline def foreach(inline f: A => Unit): Unit

Applies a side-effecting function to the contained value if defined.

Applies a side-effecting function to the contained value if defined.

Value parameters

f

the function to apply

Attributes

def get: A

Gets the value contained in the Maybe instance.

Gets the value contained in the Maybe instance.

Attributes

Returns

the contained value

Throws
NoSuchElementException

if the instance is empty

inline def getOrElse[B >: A](inline default: => B): B

Gets the value if defined, or returns a default value if empty.

Gets the value if defined, or returns a default value if empty.

Type parameters

B

a supertype of A

Value parameters

default

the default value to return if empty

Attributes

Returns

the contained value if defined, or the default value if empty

inline def isDefined: Boolean

Checks if the Maybe instance is defined.

Checks if the Maybe instance is defined.

Attributes

Returns

true if the instance is defined, false otherwise

def isEmpty: Boolean

Checks if the Maybe instance is empty.

Checks if the Maybe instance is empty.

Attributes

Returns

true if the instance is empty, false otherwise

def iterator: Iterator[A]

Creates an iterator over the contained value.

Creates an iterator over the contained value.

Attributes

Returns

an iterator with a single element if defined, or an empty iterator if empty

inline def map[B](inline f: A => B): Maybe[B]

Applies a function to the contained value if defined.

Applies a function to the contained value if defined.

Type parameters

B

the return type of the function

Value parameters

f

the function to apply

Attributes

Returns

a new Maybe containing the result of the function if defined, or Empty if empty

inline def nonEmpty: Boolean

Checks if the Maybe instance is non-empty.

Checks if the Maybe instance is non-empty.

Attributes

Returns

true if the instance is non-empty, false otherwise

inline def orElse[B >: A](inline alternative: => Maybe[B]): Maybe[B]

Returns this Maybe if defined, or an alternative Maybe if empty.

Returns this Maybe if defined, or an alternative Maybe if empty.

Type parameters

B

a supertype of A

Value parameters

alternative

the alternative Maybe to return if this is empty

Attributes

Returns

this Maybe if defined, or the alternative if empty

def show: String
inline def toLeft[X](inline right: => X): Either[A, X]

Converts the Maybe to a Left-biased Either.

Converts the Maybe to a Left-biased Either.

Type parameters

X

the type of the Right side

Value parameters

right

the value to use for the Right side if this Maybe is empty

Attributes

Returns

a Left containing the value if defined, or a Right containing the provided value if empty

def toList: List[A]

Converts the Maybe to a List.

Converts the Maybe to a List.

Attributes

Returns

a List containing the value if defined, or an empty List if empty

def toOption: Option[A]

Converts the Maybe to an Option.

Converts the Maybe to an Option.

Attributes

Returns

an Option containing the value if defined, or None if empty

inline def toRight[X](inline left: => X): Either[X, A]

Converts the Maybe to a Right-biased Either.

Converts the Maybe to a Right-biased Either.

Type parameters

X

the type of the Left side

Value parameters

left

the value to use for the Left side if this Maybe is empty

Attributes

Returns

a Right containing the value if defined, or a Left containing the provided value if empty

inline def withFilter(inline f: A => Boolean): Maybe[A]

Filters the Maybe based on a predicate.

Filters the Maybe based on a predicate.

Value parameters

f

the predicate function

Attributes

Returns

the Maybe if it's defined and satisfies the predicate, or Empty otherwise

def zip[B](that: Maybe[B]): Maybe[(A, B)]

Combines this Maybe with another Maybe into a tuple.

Combines this Maybe with another Maybe into a tuple.

Type parameters

B

the type parameter of the other Maybe

Value parameters

that

the Maybe to combine with

Attributes

Returns

a new Maybe containing a tuple of both values if both are defined, or Empty if either is empty

Implicits

Implicits

final implicit def Ops[A](maybe: Maybe[A]): Ops[A]

Provides operations on Maybe instances.

Provides operations on Maybe instances.

Attributes