Jeeves v0.1.3 Jeeves.Anonymous
Implement an anonymous service.
Usage
To create the service:
Create a module that implements the API you want. This API will be expressed as a set of public functions. Each function will be defined to accept the current state as its first parameter. If a function wants to change the state, it must end with a call to the
Jeeves.Common.update_state/2function (which will have been imported into your module automatically).For this example, we’ll call the module
MyService.Add the line
use Jeeves.Anonymousto the top of this module.
To consume the service:
Create an instance of the service with
MyJeeves.run(). You can pass initial state to the service as an optional parameter. This call returns a handle to this service instance.Call the API functions in the service, using the handle as a first parameter.
Example
defmodule Accumulator do
using Jeeves.Anonymous, state: 0
def current_value(acc), do: acc
def increment(acc, by \ 1) do
update_state(acc + by)
end
end
with acc = Accumulator.run(10) do
Accumulator.increment(acc, 3)
Accumulator.increment(acc, 2)
Accumulator.current_value(acc) # => 15
end
Options
You can pass a keyword list to use Jeeves.Anonymous:
state:valueSet the detail initial state of the service to
value. This can be overridden by passing a different value to therunfunction.showcode:booleanIf truthy, dump a representation of the generated code to STDOUT during compilation.