Maybe
Companion object for Maybe type
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Maybe.type
Members list
Type members
Classlikes
Types
Represents a defined value in a Maybe.
Represents a defined value in a Maybe.
Attributes
Value members
Concrete methods
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
Creates an empty Maybe instance.
Creates an empty Maybe instance.
Type parameters
- A
-
the type parameter of the Maybe
Attributes
- Returns
-
an Empty instance
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
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
Extensions
Extensions
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
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
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
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
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
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
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
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
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
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
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
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
Checks if the Maybe instance is defined.
Checks if the Maybe instance is defined.
Attributes
- Returns
-
true if the instance is defined, false otherwise
Checks if the Maybe instance is empty.
Checks if the Maybe instance is empty.
Attributes
- Returns
-
true if the instance is empty, false otherwise
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
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
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
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
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
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
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
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
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
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