Skip to content

Commit

Permalink
cellify: errorsAsValues option
Browse files Browse the repository at this point in the history
  • Loading branch information
hbbio committed May 24, 2024
1 parent c20e4c8 commit a0197b7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cellify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const cellify = <T>(

export type UncellifyOptions = {
getter: <T>(c: AnyCell<T>) => Pending<T, boolean> | CellResult<T, boolean>;
errorsAsValues?: boolean;
};

/**
Expand All @@ -85,7 +86,10 @@ export const uncellify = async <T>(
options: UncellifyOptions = { getter: (cell) => cell.value }
): Promise<Uncellified<T>> => {
const value = v instanceof Cell ? await options.getter(v) : v;
if (value instanceof Error) throw value;
if (value instanceof Error) {
if (options?.errorsAsValues) return value as Uncellified<T>;
throw value;
}
if (Array.isArray(value))
return Promise.all(
value.map((_element) => uncellify(_element, options))
Expand Down

0 comments on commit a0197b7

Please sign in to comment.