@lppedd/mini-result - v0.6.1
    Preparing search index...

    Variable ResConst

    Res: {
        async: <V, E>(promise: Promise<Result<V, E>>) => AsyncResult<V, E>;
        err: <E>(error: E) => Err<never, E>;
        ok: <V>(value: V) => Ok<V, never>;
        wrap: <V>(fn: () => SyncValue<V>) => Result<SyncValue<V>, unknown>;
        wrapAsync: <V>(fn: () => V | Promise<V>) => AsyncResult<V, unknown>;
    } = ...

    A factory for creating and composing Results.

    Type Declaration

    • Readonlyasync: <V, E>(promise: Promise<Result<V, E>>) => AsyncResult<V, E>

      Creates an AsyncResult from a promise that resolves to a Result.

      Useful for chaining asynchronous result operations without manually awaiting the underlying promise.

      const result = Res.async(fetchUser());
      
    • Readonlyerr: <E>(error: E) => Err<never, E>

      Creates a failed Result.

      const result = Res.err(new Error("Invalid input"));
      
    • Readonlyok: <V>(value: V) => Ok<V, never>

      Creates a successful Result.

      const result = Res.ok(successRc);
      
    • Readonlywrap: <V>(fn: () => SyncValue<V>) => Result<SyncValue<V>, unknown>

      Executes a synchronous function and wraps its return value in a Result.

      const result = Res.wrap(() => JSON.parse(jsonStr));
      
    • ReadonlywrapAsync: <V>(fn: () => V | Promise<V>) => AsyncResult<V, unknown>

      Executes a synchronous or asynchronous function and wraps its return value in an AsyncResult.

      const result = Res.wrapAsync(async () => {
      const response = await fetch(`/api/user/${userId}`);
      return response.json();
      });
    const success = Res.ok(42);
    const failure = Res.err(new Error("Invalid input"));