- Added pnpm-workspace.yaml to define package structure. - Created prepare-local-env.py script for local environment setup. - Introduced tsconfig.json for TypeScript configuration. - Added turbo.json for task management with Turbo.
26 lines
672 B
TypeScript
26 lines
672 B
TypeScript
export type Result<T, E extends Error = Error> =
|
|
| Readonly<{ isSuccess: true; data: T }>
|
|
| Readonly<{ isSuccess: false; error: E }>;
|
|
|
|
export const Result = {
|
|
ok<T>(data: T): Result<T, never> {
|
|
return Object.freeze({ isSuccess: true, data });
|
|
},
|
|
fail<E extends Error>(error: E): Result<never, E> {
|
|
return Object.freeze({ isSuccess: false, error });
|
|
},
|
|
};
|
|
|
|
export class Maybe<T> {
|
|
private constructor(private readonly value: T | undefined) {}
|
|
static some<T>(value: T): Maybe<T> {
|
|
return new Maybe(value);
|
|
}
|
|
static none<T>(): Maybe<T> {
|
|
return new Maybe<T>(undefined);
|
|
}
|
|
getOrUndefined(): T | undefined {
|
|
return this.value;
|
|
}
|
|
}
|