Optional<ItemType>the Optional to compare againstReturns true when both are empty, or both hold equal values.
A value that is there or is not, and the methods that test, read, transform and fall back from it.
A value that is there or is not: #Value holds an item, and #Empty holds nothing.
Every Method that can come back empty answers one of these. The Choice nests, so #Value(#Empty) is not #Empty.
Taught on: Optional.
namespace Optional<infer ItemType> for Optional<ItemType>NestedOptional for Optional<Optional<ItemType>> in NestedA view is a namespace for a narrower type. A value of that type has the view's methods on top of its own.
on Optional<ItemType>
Answers whether the Optional is the given one, or whether it holds the given bare value.
Two Optionals are equal when they are the same Case and hold equal values. An empty Optional is never equal to a bare value. An Optional holding an Optional reaches the first entry, so #Value(#Empty)::is(#Empty) asks about the receiver and answers false. The Method is available whenever the payload conforms to Equatable.
Optional<ItemType>the Optional to compare againstReturns true when both are empty, or both hold equal values.
ItemTypethe bare value to compare againstReturns true when the Optional holds a value equal to it; false when it is empty.
on Optional<ItemType>
Answers whether the Optional differs from the given one, or whether it does not hold the given bare value.
An empty Optional holds no bare value, so it always differs from one. The Method is available whenever the payload conforms to Equatable.
Optional<ItemType>the Optional to compare againstReturns true when the two differ in Case or in value.
ItemTypethe bare value to compare againstReturns true when the Optional is empty or holds a different value.
on Optional<ItemType>
Answers the Optional as a String, written Value(…) or Empty.
The payload renders through its own toString, and a String payload is quoted: #Value("a") answers Value("a"). A String prints bare on its own and quoted inside a structure. The Method is available whenever the payload conforms to Printable.
Returns the text Value(…) around the payload, or Empty.
on Optional<ItemType>
Answers whether the Optional holds a value, or holds a value the check accepts.
Returns true when there is a value, or when the check accepts the value.
Answers whether the Optional holds a value.
Returns true when there is a value.
Answers whether the Optional holds a value the check accepts.
An empty Optional answers false, and the check does not run.
(_: ItemType) -> Booleanthe question asked of the valueReturns true when there is a value and the check accepts it.
on Optional<ItemType>
Answers whether the Optional holds no value, the opposite of hasValue.
Returns true when there is no value.
on Optional<ItemType>
Answers the value, or the given fallback when there is none.
The call collapses an Optional back to a bare value: list::firstItem()::value(defaultingTo 0).
ItemTypethe value to answer with when there is noneReturns the value, or the fallback in its place.
on Optional<ItemType>
Answers the value transformed, wrapped in an Optional.
An empty Optional answers empty, and the transform does not run. This is List::map for the at-most-one case.
(_: ItemType) -> Otherthe transform to run on the valueReturns the transformed value in an Optional, or an empty Optional.
on Optional<ItemType>
Answers with the Optional the step answers for the value.
The two Optionals do not nest: the answer has one level. An empty Optional answers empty, and the step does not run.
(_: ItemType) -> Optional<Other>the step to run on the valueReturns the Optional the step answers, or an empty Optional.
on Optional<ItemType>
Answers the Optional when its value passes the check, and empty otherwise.
An empty Optional answers empty, and the check does not run. This is List::everyItem(where:) for the at-most-one case.
(_: ItemType) -> Booleanthe question asked of the valueReturns the Optional unchanged when the value passes, an empty Optional otherwise.
on Optional<ItemType>
Answers the Optional when it holds a value, and the given Optional otherwise.
A chain of calls reads as a list of fallbacks, and the first value in it decides the answer. Two empty Optionals answer empty. The Argument is read whether or not the receiver holds a value.
Optional<ItemType>the Optional to fall back onReturns the receiver when it holds a value, and the Argument in its place otherwise.
on Optional<ItemType>
Answers the two values in one Record, and empty when either Optional is empty.
This is List::pair(with:) for the at-most-one case. Both values are needed, so one empty Optional answers empty.
Optional<Other>the Optional to pair the value withReturns a Record holding this value under first and the other under second, or an empty Optional.
on Optional<ItemType>
Answers a List holding the value, and the empty List when there is none.
The answer holds one item at most. It is the bridge to the Methods a List answers, and OptionalList::values() is the bridge back.
Returns the List of the value, or the empty List.
on Optional<ItemType>
Answers the value as a Result, failing with the given reason where there is none.
An Optional says that there is no value, and a Result says why. The reason is read whether or not it is used.
The reason's own Type decides the Result's failure Type. A bare #NotFound binds it to that Case alone, and a Problem#NotFound written out does the same. The next call in the chain then works on a Result of a Type it does not expect. Bind the reason to a Constant annotated with the Choice to say the Choice.
FailureTypethe reason to fail with where there is no valueReturns the value in a Result, or the reason as a failure.
on Optional<Optional<ItemType>>
Answers the inner Optional, one level down.
An empty outer Optional answers empty.
Returns the flattened Optional.