Apama 10.15.3 | Release Notes | What's New In Apama 10.15.3 | EPL enhancements in 10.15.3
 
EPL enhancements in 10.15.3
Apama 10.15.3 includes the following EPL enhancements:
*A new EPL library has been added to support programming in a functional style for quicker development, fewer for loops, and more concise and readable code. For example:
// Calculate the average of the values in the sequence = 20
Fn.reduce([10, 20, 30], Fn.mean());

// Filter strings by regular expression using the string.matches action = ["Hello Alice", "Hello Al"]
Fn.filter(["Hello Alice", "Hello Bob", "Hello Al"], Fn.callAction("matches", ["Hello Al.*"]));
// Use Functional() to chain multiple operations: filter out odd numbers, then reduce the sequence to a single value containing the sum = 70
Functional([10, -5, 20, 40]).filter(Fn.even).reduce(Fn.sum);
The library provides similar capabilities to Python's functools module. It can be added to Apama projects with a new Functional EPL Library bundle which provides two main EPL types: com.apama.functional.Fn and com.apama.functional.Functional. These provide functional operations such as map, filter and reduce in both a functional style and a fluent style. They operate on EPL sequence and dictionary containers and on a new "generator" concept that lazily calculates infinite lists.
There is support for partial binding of action arguments:
Fn.map(["Bob", "Alice"], Fn.partial(Fn.concat, "Hello ")).toString(); // = ["Hello Bob","Hello Alice"]
There are also some new actions to make event sending and listening more concise, including the following:
// Initialize an event (providing only the subset of fields you care about), send and extract the request id for use in listener
// (it is also possible to initialize event fields by name rather than by position)
on MyResponse(reqId=<integer> Fn.sendToChannel(MyEvent.SEND_CHANNEL,
Fn.setFields(new MyEvent, [<any>createRequestId(), "/myrequest"])
).getEntry("reqId") ) as response
{
...
}

// Listen for events with an identifier matching each value from this sequence, and calls a completion action when all have arrived
// (similar to an EPL "and" event expression). A different callback is executed if the specified timeout expires.
Functional(sequenceIDs)
.waitForAllCompleted("MyResponse", "id", onCompleted)
.onTimeout(TIMEOUTSECS, onTimeout);
For detailed information, see Using Functional Operations in EPL. See also the API Reference for EPL (ApamaDoc) for detailed information on com.apama.functional.
*For an event type with 4 fields, it is now valid to use the positional syntax for a subset of those. For example, on E(1, 2, 3) is now valid and is semantically equivalent to E(1, 2, 3, *). See also Using positional syntax to listen for events with particular content.
*The at() event operator in EPL for listeners can now be provided with a time zone as an optional final argument. This can be in string form or (recommended) one of the new constants in the TimeZone namespace. For more details, see Triggering event listeners at specific times and the TimeZone namespace in the API Reference for EPL (ApamaDoc) . The new constants can also be used with the TimeFormat event library.