Option
function Option<A>(type: A): ProvableInferPureFrom<A, Option<InferProvable<A>, InferValue<A>>, InferValue<A> | undefined> & (option: {
"isSome": Bool;
"value": InferProvable<A>;
}) => Option<InferProvable<A>, InferValue<A>> & {
"from": Option<InferProvable<A>, InferValue<A>>;
"fromValue": Option<InferProvable<A>, InferValue<A>>;
"none": Option<InferProvable<A>, InferValue<A>>;
}
Define an optional version of a provable type.
Type parameters
• A extends ProvableType
Parameters
• type: A
Returns
ProvableInferPureFrom
<A
, Option
<InferProvable
<A
>, InferValue
<A
>>, InferValue
<A
> | undefined
> & (option
: {
"isSome"
: Bool
;
"value"
: InferProvable
<A
>;
}) => Option
<InferProvable
<A
>, InferValue
<A
>> & {
"from"
: Option
<InferProvable
<A
>, InferValue
<A
>>;
"fromValue"
: Option
<InferProvable
<A
>, InferValue
<A
>>;
"none"
: Option
<InferProvable
<A
>, InferValue
<A
>>;
}
Example
class OptionUInt64 extends Option(UInt64) {}
// create an optional UInt64
let some = OptionUInt64.from(5n);
let none = OptionUInt64.none();
// get back a UInt64
let five: UInt64 = some.assertSome('must have a value');
let zero: UInt64 = none.orElse(0n); // specify a default value