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