matches<K>(variant: K): this is EnumNarrowed<this, V, K>
Returns true if the variant is passed variant.
Prop
Type
Default
variant
K
-
import { Ok, Err } from "tnum/std";const res = Ok(200);// short version of this code is `res.isOk()`.if (res.matches("Ok")) { res.takeVariantValue(); // result-type is number.}
This method is alternative of match expression. You can catch variant and containig value by arm(type: [variant-name](value): T). _ arm catches uncaught variants. You must write arms so that it catches all variants. This method returns the return value of arm that caught the variant.
Prop
Type
Default
arms
EnumMatchArms<V, T>
-
import { Some } from "tnum/std";const optName = Some("hoge");// short version of this code is `optName.unwrapOr("[no name]");`.const name: string = optName.match({ Some: (name) => name, _: () => "[no name]",});