Documentation of Cherry Framework
Functional Agent and Functional Missions
'I can be as functional and asynchronous as you want', said the Agent...
As part of the Cherry Framework we provide a FunctionalAgent
implementation of an Agent who is able to perform missions in the form of Functions:
e.g.
FunctionalMission<FunctionalAgent> savingInMemory = anAgent -> {
anAgent.keepsInMind("test","test");
return asSystemSupport;
}
FunctionalAgent theAgent = FunctionalAgent.functionalAgent();
myFunctioanAgent.performs(savingInMemory);
There are several implementations of functions so you can have multiple input types for your missions, e.g.
String result = theAgent.performs((integer, integer2, integer3, agent) -> agent.usingThe(Additioner.class).addAndGetAsString(integer, integer2, integer3), 1, 2, 3);
And you can also verify the results using verifyAsFunctional(FunctionalAgent) e.g.
theAgent.obtains(new Additioner());
final Functions.FunctionalMission2<Integer, Integer, String> theFunction = (integer1, integer2, agent) -> agent.usingThe(Additioner.class).addAndGetAsString(integer1, integer2);
verifyAsFunctional(theAgent).that(theFunction, 1, 2, is("3"));
In this example, we can see that 'theFunction' is a FunctionalMission2 implementation because it accepts 2 input types - in our case integers - and returns a String result. FunctionalAgent is happy to accept this sort of lambda expressions as missions. We have several implementations more input types (e.g. FunctionalMission3, FunctionalMission4 etc).
CompletableFutures
FunctionalAgent is also enriched with the ability to asynchronously perform functions, as follows:
assertThat(functionalAgent.performsAsync(asAgent -> "desserts").thenApply(s -> new StringBuffer(s).reverse().toString()).get(),is("stressed"));