Effect notes: fn
macwright.com·5d
Effect Handlers
Preview
Report Post

TIL about Effect.fn

I started reading some of effect-solutions and learned about Effect.fn. This method helps with one of the core weirdnesses of Effect, that so much of the documentation doesn’t really show you functions with arguments, which are a big part of programming. So a classic Effect pattern that I’ve been using is like this:

export function downloadFile(
key: string,
location: string
): Effect.Effect<
void,
NotFoundError | PlatformError | UnknownException,
FileSystem.FileSystem
> {
return Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
let dest = localPath(key);
yield* downloadAndFileToTemp(key);
yield* fs.copyFile(dest, location);
}).pipe(Effect.withSpan("downlo...

Similar Posts

Loading similar posts...