Error Propagation
use
import { ResultAsync } from 'funkcia';
declare const safeReadFile: (path: string) => ResultAsync<string, NodeFSError>;
declare const safeWriteFile: (path: string, content: string) => ResultAsync<string, NodeFSError>;
// ┌─── ResultAsync<string, NodeFSError>
// ▼
const mergedContent = ResultAsync.use(async function* () {
const fileA = yield* safeReadFile('data.txt');
const fileB = yield* safeReadFile('non-existent-file.txt'); // returns ResultAsync.Error immediately
return safeWriteFile('output.txt', `${fileA}\n${fileB}`); // doesn't run
});
// Output: ResultAsync<string, NodeFSError>fn
Understanding the use method
Last updated
Was this helpful?