Hacker News new | ask | show | jobs
by homami 1407 days ago
I fully recommend this. The fp-ts is quite readable for JavaScript. Combine it with io-ts and you have a robust way of handling user inputs:

    pipe(
      decoder.decode(req.body)
      , E.mapLeft(_ex => new InputValidationError(decoder.decode(req.body)))
      , RTE.fromEither
      , RTE.chain(handleInput)
      , RTE.match(
        error => {
          res.status(500);
          res.send(error)
        },
        result =>  {
          res.send(result)
        }
      )
    )(reader)