return closure to compose functions that may throw errors
composition
This approach works well in most scenarios, however, it doesn’t when we anticipate a potential failure in one (or more) of the earlier functions and would like to handle it in one (or more) of the latter ones.
closures to the rescue
In functional programming there is a concept of a container - function is a type of a container. We can transform functions to return functions and by doing so achieve the required functionality.
This is not the only way and most probably not the best either (see Fantasy Land) - but gets the job done without external dependencies, a lot of extra code and a need to have a pre-existing FP knowledge.