Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper combinators for entity readers on entities #141

Merged
merged 1 commit into from
Mar 14, 2015

Conversation

dwhjames
Copy link
Owner

Suppose that there is a customer entity with a primaryAddress attribute that is a cardinality one reference to a address entity, and furthermore, that an address entity has a city attribute (cardinality one, string).

Currently in Datomisca, one would express an entity reader on customers that extracts the city of the primary address as:

primaryAddress.read[Entity].map(e => e.read[String](city))

With the andThen combinator, this can more succinctly be expressed as:

primaryAddress.read[Entity] andThen city.read[String]

Now suppose that a customer entity also has a cardinality many reference attribute addresses that references all address entities associated with the customer.

To get the set of all cities, one would currently write

addresses.read[Set[Entity]].map(_.map(e => e.read[String](city)))

With the andThenAll combinator, this can more succinctly be expressed as:

addresses.read[Set[Entity]] andThenAll city.read[String]

Finally, suppose that address entities have a telephones attribute (cardinality many, string).

Then to get the set of all telephone numbers, one would currently write

addresses.read[Set[Entity]].map(_.flatMap(e => e.read[Set[String]](telephones)))

With the andThenFlatten combinator, this can more succinctly be expressed as:

addresses.read[Set[Entity]] andThenFlatten telephones.read[Set[String]]

helpers for chaining entities readers onto cardinality one and many reference attributes
@rjsvaljean
Copy link

👍

dwhjames added a commit that referenced this pull request Mar 14, 2015
Helper combinators for entity readers on entities
@dwhjames dwhjames merged commit fca1ff4 into develop Mar 14, 2015
@dwhjames dwhjames deleted the topic/entity-reader branch March 14, 2015 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants