Slide 26
Slide 26 text
© 2023 Leverages Co., Ltd.
pipeの導入
26
import { Either, left, right, flatMap, tap, mapLeft } from "fp-ts/lib/Either";
import { pipe } from "fp-ts/function";
function createUser(param: { email: string; password: string }) {
const convertValidationError = (error: {
type: "InvalidEmail" | "InvalidPassword";
message: string;
}) => (...)
const convertSaveError = (error: { message: string }) => (...)
return pipe(
pipe(
validateInput(param),
mapLeft(convertValidationError)),
flatMap(() => pipe(
save(param),
mapLeft(convertSaveError) )),
tap(() => sendRegisteredEmail(param.email))
);
}