TaskEither and io-ts
import { pipe } from "fp-ts/lib/pipeable";
import * as E from "fp-ts/lib/Either";
import * as TE from "fp-ts/lib/TaskEither";
function getStuff(u: string): TE.TaskEither<Error, unknown> {
return TE.tryCatch(
() =>
fetch(u).then(res => {
if (!res.ok) {
throw new Error(`fetch failed with status: ${res.status}`);
}
return res.json();
}),
E.toError
);
}Last updated