gizlang:core
Values that may fail or be absent. try unwraps the first case and returns any other case from the enclosing function.
import * as Core from "gizlang:core";Types
Result
type Result<T, E> = | { kind: "ok"; value: T; } | { kind: "err"; error: E; }The outcome of an operation that can fail: ok with the value, or err with the error.
Option
type Option<T> = | { kind: "some"; value: T; } | { kind: "none"; }An optional value: some with the value, or none.
Tuple2
type Tuple2<A, B> = { first: A; second: B; }TypeScript's tuples: [A, B] is Tuple2<A, B>, t[0] its first, and [a, b] where one is expected makes it.
Opaque: create and use it through this module's functions.
Tuple3
type Tuple3<A, B, C> = { first: A; second: B; third: C; }Three values of any types, as one value.
Opaque: create and use it through this module's functions.
Tuple4
type Tuple4<A, B, C, D> = { first: A; second: B; third: C; fourth: D; }Four values of any types, as one value.
Opaque: create and use it through this module's functions.
Tuple5
type Tuple5<A, B, C, D, E> = { first: A; second: B; third: C; fourth: D; fifth: E; }Five values of any types, as one value.
Opaque: create and use it through this module's functions.
Tuple6
type Tuple6<A, B, C, D, E, F> = { first: A; second: B; third: C; fourth: D; fifth: E; sixth: F; }Six values of any types, as one value.
Opaque: create and use it through this module's functions.
Error
type Error = { name: string; message: string; cause: Option<string>; }TypeScript's standard error: what throw new Error("...") throws and throws Error names. name is its kind ("Error",
or a domain's, such as "JsonError"), message says what went wrong, and cause is the message of the error under it.
name:stringmessage:stringcause:_gizlang_sdk_core.Option<string>
Functions
newError
function newError(message: string): Errornew Error(message).
raise
function raise<E>(value: E): void throws EFails with VALUE: TypeScript's throw value; in a function that does not throw (parser throwValue), so the
failure faults R004 and prints VALUE, as a throw that nothing catches does.
moduleGet
function moduleGet<T>(name: string, first: () => T): TThe value of the module-level let bound to name (compiler: checker moduleState); its first use makes it with
first(). A read of the name is this call.
moduleSet
function moduleSet<T>(name: string, first: () => T, value: T): voidGives the module-level let bound to name the value value: an assignment to the name is this call. first is
its initializer, which the assignment makes unneeded.
Methods
Result.valueOr
function Result.valueOr<T, E>(self: Result<T, E>, fallback: T): TThe value of a Result that succeeded, else fallback.
Result.unwrap
function Result.unwrap<T, E>(self: Result<T, E>): TThe value, or fault R004 (a failed assert, with its call path) when there is none: for a program that cannot go on without it, such as a script.
Option.unwrap
function Option.unwrap<T>(self: Option<T>): TThe value of an Option; it is a defect (R004) when there is none.
Option.isSome
function Option.isSome<T>(self: Option<T>): boolWhether the Option has a value.
Result.isOk
function Result.isOk<T, E>(self: Result<T, E>): boolWhether the Result succeeded.
Option.map
function Option.map<T, U>(self: Option<T>, f: (value: T) => U): Option<U> effects { f, fail }Map the payload of a present value, preserving absence.
Option.andThen
function Option.andThen<T, U>(self: Option<T>, f: (value: T) => Option<U>): Option<U> effects { f, fail }Chain another optional computation without nesting the two cases.
Result.map
function Result.map<T, E, U>(self: Result<T, E>, f: (value: T) => U): U throws E effects { f, fail }Transform a successful value, preserving a typed error.
Result.mapErr
function Result.mapErr<T, E, F>(self: Result<T, E>, f: (error: E) => F): T throws F effects { f, fail }Change the error without touching a successful value.
Result.andThen
function Result.andThen<T, E, U>(self: Result<T, E>, f: (value: T) => Result<U, E>): U throws E effects { f, fail }Chain another fallible computation with the same error type.