MostlyAdequate / mostly-adequate-guide

Mostly adequate guide to FP (in javascript)
Other
23.45k stars 1.87k forks source link

Chapter 8 : Question about solution of the last exercise #577

Closed psychobaatezu closed 4 years ago

psychobaatezu commented 4 years ago

Hi! Really interesting book so far. Enjoying it. But I have difficulty to understand how the solution of the last exercise could work.

const validateName = ({ name }) => (name.length > 3
  ? Either.of(null)
  : left('Your name need to be > 3')
);

const saveAndWelcome = compose(map(showWelcome), save);

const register = compose(
  either(IO.of, saveAndWelcome),
  validateUser(validateName),
);

How could saveAndWelcome actually save the user if it receives an Either.of(null) from validateName?

psychobaatezu commented 4 years ago

Nevermind... Figured it out.