Agency :: an abstraction layer on top of Agent

Agency is a tiny library reducing a boilerplate on top of Agent.

It backs up any container implementing Access and exposes transparent CRUD/Access-like methods, as well as before_***/1 and after_***/1 callbacks for clean client API implementation.

One might want to use this library to reduce a boilerplate needed to agentify the container for performing basic CRUD. before_***/1 callbacks, accepting a key and returning a key, could be used for transparent mapping of keys on the boundary of server API calls. after_***/1 callbacks, similarly, can be used to transform raw values returned from the server API (the backed up container.)

It also implements Access on its own; this is slightly counter-idiomatic and consumers are discouraged to use it in most cases but saving keystrokes accessing data in deeply nested containers.


Is the after_get sort of like :atomics.add_get/3?

Not sure I fully get the idea of the before_* and after_* functions.

Nope. Agent documentation explicitly advises to use the client API for anything around the values and the server API to deal with a container. These functions make client API more explicit. The flow would be

key = before_get(key)
value = Agent.get(key)

In 95% of cases they would be NoOp.