From 889b7b593bcc13353933b4c6d71704a9e49c14ba Mon Sep 17 00:00:00 2001 From: bkiac Date: Mon, 15 Apr 2024 11:36:45 +0200 Subject: [PATCH] Rename variant symbols --- src/common.ts | 4 ++-- src/option.ts | 16 ++++++++-------- src/result.ts | 18 +++++++++--------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/common.ts b/src/common.ts index 1ad8f70..32caa2c 100644 --- a/src/common.ts +++ b/src/common.ts @@ -1,2 +1,2 @@ -export const Variant = Symbol("n"); -export const Value = Symbol("x"); +export const variant = Symbol("variant"); +export const value = Symbol("value"); diff --git a/src/option.ts b/src/option.ts index add3946..3f2cee6 100644 --- a/src/option.ts +++ b/src/option.ts @@ -1,6 +1,6 @@ import {AsyncOption} from "./async_option"; import {AsyncResult} from "./async_result"; -import {Variant, Value} from "./common"; +import {variant, value} from "./common"; import {Panic} from "./error"; import {Err, Ok, type Result} from "./result"; import {inspectSymbol} from "./util_internal"; @@ -16,12 +16,12 @@ export type OptionMatchAsync = { }; export class OptionImpl { - private readonly [Variant]: boolean; - private readonly [Value]: T | undefined; + private readonly [variant]: boolean; + private readonly [value]: T | undefined; constructor(some: boolean, x: T) { - this[Variant] = some; - this[Value] = x; + this[variant] = some; + this[value] = x; } private unwrapFailed(message: string): never { @@ -29,15 +29,15 @@ export class OptionImpl { } get isSome(): boolean { - return this[Variant]; + return this[variant]; } get isNone(): boolean { - return !this[Variant]; + return !this[variant]; } get value(): T | undefined { - return this[Value]; + return this[value]; } /** diff --git a/src/result.ts b/src/result.ts index 72e516a..f0d0029 100644 --- a/src/result.ts +++ b/src/result.ts @@ -2,7 +2,7 @@ import {Panic} from "./error"; import {inspectSymbol} from "./util_internal"; import {Option, Some, None} from "./option"; import {AsyncResult} from "./async_result"; -import {Variant, Value} from "./common"; +import {variant, value} from "./common"; export type ResultMatch = { Ok: (value: T) => A; @@ -15,12 +15,12 @@ export type ResultMatchAsync = { }; export class ResultImpl { - private readonly [Variant]: boolean; - private readonly [Value]: T | E; + private readonly [variant]: boolean; + private readonly [value]: T | E; constructor(ok: boolean, x: T | E) { - this[Variant] = ok; - this[Value] = x; + this[variant] = ok; + this[value] = x; } private unwrapFailed(message: string): never { @@ -28,19 +28,19 @@ export class ResultImpl { } get isOk(): boolean { - return this[Variant]; + return this[variant]; } get isErr(): boolean { - return !this[Variant]; + return !this[variant]; } get value(): T | undefined { - return this.isOk ? (this[Value] as T) : undefined; + return this.isOk ? (this[value] as T) : undefined; } get error(): E | undefined { - return this.isErr ? (this[Value] as E) : undefined; + return this.isErr ? (this[value] as E) : undefined; } *[Symbol.iterator](): Iterator, T, any> {