MCPcopy Index your code
hub / github.com/expo/results

github.com/expo/results @v1.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.0 ↗ · + Follow
14 symbols 17 edges 2 files 3 documented · 21% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

@expo/results

Tests codecov

An efficient, standards-compliant library for representing results of successful or failed operations. A result object represents the result of an operation that can either return a value successfully or fail. Typically we'd simply either return a value or throw an error, but sometimes we perform multiple operations as a batch, some of which may succeed and others fail. Since we can't simultaneously return values and throw errors, we instead return collections of result objects. This allows a batch operation to return values for successful operations and errors for failed ones without loss of information, namely the errors. (In contrast, sometimes it is appropriate for a batch operation to return just successful values and omit values for failed operations.)

Usage

Using Results

import { Result, result } from '@expo/results';

const results = await fetchWebPages(['https://expo.dev', 'http://example.com']);
for (const result of results) {
  if (result.ok) {
    console.log(result.value);
  } else {
    console.error(result.reason);
  }
}

Creating Results

import { Result, result } from '@expo/results';

/**
 * The purpose of this result API is to let you write functions that can
 * partially succeed and partially fail and return all of that information to
 * the caller.
 */
function fetchWebPages(urls: string[]): Promise<Result<string>[]> {
  return Promise.all(urls.map(fetchWebPage));
}

function fetchWebPage(url: string): Promise<Result<string>> {
  try {
    const response = await fetch(url);
    const text = await response.text();
    return result(text);
  } catch (e) {
    return result(e);
  }
}

Core symbols most depended-on inside this repo

result
called by 11
src/results.ts
asyncResult
called by 6
src/results.ts
enforceAsyncResult
called by 4
src/results.ts
enforceValue
called by 0
src/results.ts
enforceError
called by 0
src/results.ts
toJSON
called by 0
src/results.ts
constructor
called by 0
src/results.ts
constructor
called by 0
src/results.ts

Shape

Function 6
Class 5
Method 2
Enum 1

Languages

TypeScript100%

Modules by API surface

src/results.ts14 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add results \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact