Skip to main content

Option

function Option<A>(type: A): Provable<Option<InferProvable<A>, InferValue<A>>, InferValue<A> | undefined> & {
"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 Provable\<any, any>

Parameters

type: A

Returns

Provable\<Option\<InferProvable\<A>, InferValue\<A>>, InferValue\<A> | undefined> & { "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

Source

lib/provable/option.ts:37