scalaz Validation, neo4j and for-comprehensions
I have an app that uses neo4j as the underlying database. Similar to all database applications, I also have a data access layer that helps abstract out the use of neo4j.
The data access layer takes in string parameters, mostly, finds the neo4j nodes or relationships then manipulates the those objects to create a new object.
In this access layer, I must gather several different objects together to process. For example, the start node, the end node, another node that holds my dynamic type system, and various other objects.
When assembling these nodes, I typically find the pattern to go something like this:
The standard approach that I use for error handling is to throw as few exceptions as possible. Instead, I would rather gather the "error" messages together and return them to the caller to handle. While this may seem like the same complexity, with its detractions, as forcing the caller to handler checked exceptions (except there are no checked exceptions in scala), I do want the caller to use non-breaking error handling so that results, especially if its a failure due to the caller's user-oriented input parameters, get back to the user in an user-friendly way.
- Check the input parameters
- Find the objects. This step typically takes an input parameter, then finds the object.
- Then use that object, in sequence, to find another object and so on.
- With all the objects assembled, create the new object
See the rest of this and the code at github.