Here is a comparison of two pieces of code that do basically the same thing.
So what we have here is a chain of functions depending on each other, each consecutive takes the result of the previous one for further processing. If either of them fails, the rest shall not be executed.
- validate parameters received from the outside world in a Hash
- convert one of the parameters into an object
- do a search in the database
You could express the whole operation like this:
find_in_db(convert_to_bson_id(get_id( params )))
The important thing is, I assume using a debugger (also sometime puts-driven-development) an expensive operation on the human side, and hence should be avoided. The implication is, that each operation needs to report errors in a clean and predictive way.
You can find more examples and a description of the monadic stuff (Try, Either) used here https://github.com/pzol/monadic