com.apamax.functional
Event Fn


Provides functional operations on EPL containers, such as map, reduce, filter and slice.

Also provides generators which can be used as input to the functional operations.

eg: Fn.slice(Fn.map(Fn.filter(Fn.count(), (integer i)->i%2=0), (integer i)->i*2), 2, 8, 2);
Action summary
 booleanstatic _all(any seq)

Logical 'AND' over a sequence of booleans
 booleanstatic _any(any seq)

Logical 'OR' over a sequence of booleans
 action<any> returns booleanstatic _not(any pred)

A predicate which inverts the value of another predicate.
 com.apamax.functional.Generatorstatic accumulate(any container, any func)

Returns a generator which accumulates over the underlying container, returning the result after accumulating each item. Similar to reduce, but returns a generator for each item in turn, rather than just the final total. The initial value of the accumulator is the default value of func's return type (TYPEB).
 com.apamax.functional.Generatorstatic accumulateFrom(any start, any container, any func)

Returns a generator which accumulates over the underlying container, returning the result after accumulating each item. Similar to reduce, but returns a generator for each item in turn, rather than just the final total.
 anystatic argmap(any container, any func)

Iterates through a sequence, or a generator and uses the result as a list of arguments with which to invoke a function. These inner sequences will be treated as a list of arguments to the given function, or a single argument to that function. Each generated item will be the result of calling func with the next set of arguments.
 stringstatic concat(string acc, string i)

Action which concatenates strings using accumulate or reduce.
 com.apamax.functional.Generatorstatic count()

Returns a generator producing sequential integers with the first one being 0.
 com.apamax.functional.Generatorstatic cycle(any seq)

Iterates through a sequence of items and continues looping forever.
 booleanstatic even(integer i)

A predicate which returns true if the argument is even.
 integerstatic filter(any container, any func)

Takes either a sequence, a dictionary or a generator and filters the contents using a boolean predicate func.
 com.apamax.functional.Generatorstatic generator(any func)

Create a generator from a function, which is passed the previous value and should return the next value. The initial value will be a default-initialized TYPE and the result of first generation will be the result of invoking func on that default-initialized value. To specify the initial value, use generateFrom.
 com.apamax.functional.Generatorstatic generatorFrom(any start, any func)

Create a generator from a function, which is passed the previous value and should return the next value.
 integerstatic increment(integer i)

Increments the given integer
 booleanstatic istrue(boolean b)

A predicate which returns true if the argument is true.
 integerstatic map(any container, any func)

Takes either a sequence, a dictionary or a generator and maps the contents using a function.
 anystatic mul(any acc, any i)

Action for multiplying together the values in a sequence or generator of integer, float or decimal using accumulate or reduce.
 booleanstatic negative(any i)

A predicate which returns true if the argument is negative.
 booleanstatic odd(integer i)

A predicate which returns true if the argument is odd.
 com.apamax.functional.Partialstatic partial(any func, any args)

Partially execute a function, providing some arguments, to be later executed with the remaining arguments. Arguments must be provided left-to-right for the function call to be invoked. eg: Partial p := Fn.partial(concatFn, "Hello"); <string>p.exec(" world"); Partial objects can be passed to any of the other actions on Fn where an action would be expected.
 booleanstatic positive(any i)

A predicate which returns true if the argument is positive (not including 0).
 sequence<integer>static range(integer start, integer end, integer stride)

Returns a range of integers from start (inclusive) to end (exclusive), incrementing stride each time.
 anystatic reduce(any container, any func)

Takes either a sequence or a dictionary and accumulates all of the values using an accumulator function, returning the final result.
 anystatic reduceFrom(any accumulator, any container, any func)

Takes either a sequence or a dictionary and accumulates all of the values using an accumulator function, returning the final result.
 com.apamax.functional.Generatorstatic repeat(any item)

Repeats the given element forever.
 anystatic sequenceOf(any item, integer n)

Returns a sequence containing the given item the given number of times.
 anystatic slice(any container, integer start, integer end, integer stride)

Takes either a sequence or a generator and returns a given sub-range as a finite sequence. If it is passed a generator, it will invoke the generator sufficient times immediately to satisfy the slice.
 anystatic sum(any acc, any i)

Action for adding up a sequence or generator of integer, float or decimal using accumulate or reduce.
 booleanstatic whole(any i)

A predicate which returns true if the argument is a whole number.
 
Action detail

_all

boolean static _all(any seq)
Logical 'AND' over a sequence of booleans
Parameters:
seq - sequence of booleans. Return true iff none of the items in the sequence are false. If seq is empty, returns true.

_any

boolean static _any(any seq)
Logical 'OR' over a sequence of booleans
Parameters:
seq - sequence of booleans. Return false iff none of the items in the sequence are true. If seq is empty, returns false.

_not

action<any> returns boolean static _not(any pred)
A predicate which inverts the value of another predicate.
Parameters:
pred

accumulate

com.apamax.functional.Generator static accumulate(any container, any func)
Returns a generator which accumulates over the underlying container, returning the result after accumulating each item. Similar to reduce, but returns a generator for each item in turn, rather than just the final total. The initial value of the accumulator is the default value of func's return type (TYPEB).
Parameters:
container - The sequence, dictionary or generator to accumulate.
func - An action<TYPEB,TYPEA> returns TYPEB action or lambda which accumulates each item in turn and returns the new total.
Returns:
A generator which returns each accumulated item in turn.
See Also:
reduce - 

accumulateFrom

com.apamax.functional.Generator static accumulateFrom(any start, any container, any func)
Returns a generator which accumulates over the underlying container, returning the result after accumulating each item. Similar to reduce, but returns a generator for each item in turn, rather than just the final total.
Parameters:
start - The initial value of the accumulator; must have the same type as func's return type (TYPEB).
container - The sequence, dictionary or generator to accumulate.
func - An action<TYPEB,TYPEA> returns TYPEB action or lambda which accumulates each item in turn and returns the new total.
Returns:
A generator which returns each accumulated item in turn.
See Also:
reduceFrom - 

argmap

any static argmap(any container, any func)
Iterates through a sequence, or a generator and uses the result as a list of arguments with which to invoke a function. These inner sequences will be treated as a list of arguments to the given function, or a single argument to that function. Each generated item will be the result of calling func with the next set of arguments.
Parameters:
container - A sequence or a generator.
func - A function which takes each item in container and returns a result.

concat

string static concat(string acc, string i)
Action which concatenates strings using accumulate or reduce.
Parameters:
acc
i

count

com.apamax.functional.Generator static count()
Returns a generator producing sequential integers with the first one being 0.

cycle

com.apamax.functional.Generator static cycle(any seq)
Iterates through a sequence of items and continues looping forever.
Parameters:
seq - The sequence of values to iterate over
Returns:
A generator which iterates over seq

even

boolean static even(integer i)
A predicate which returns true if the argument is even.
Parameters:
i

filter

integer static filter(any container, any func)
Takes either a sequence, a dictionary or a generator and filters the contents using a boolean predicate func.

eg: Fn.filter(numbers, (integer i)->i%2=0)

Specifically, given:
Parameters:
container - A sequence, dictionary or generator.
func - A boolean predicate function or lambda.
Returns:
The container filtered using the predicate function.

generator

com.apamax.functional.Generator static generator(any func)
Create a generator from a function, which is passed the previous value and should return the next value. The initial value will be a default-initialized TYPE and the result of first generation will be the result of invoking func on that default-initialized value. To specify the initial value, use generateFrom.

eg: Fn.generator((integer i)->i+1)
Parameters:
func - An action<TYPE> returns TYPE action or lambda which takes the previous value and returns the next value.
Returns:
A generator for TYPE.

generatorFrom

com.apamax.functional.Generator static generatorFrom(any start, any func)
Create a generator from a function, which is passed the previous value and should return the next value.

eg: Fn.generatorFrom(100, (integer i)->i+1)
Parameters:
start - The value to pass to func to generate the first generation.
func - An action<TYPE> returns TYPE action or lambda which takes the previous value and returns the next value.
Returns:
A generator for TYPE.

increment

integer static increment(integer i)
Increments the given integer
Parameters:
i

istrue

boolean static istrue(boolean b)
A predicate which returns true if the argument is true.
Parameters:
b

map

integer static map(any container, any func)
Takes either a sequence, a dictionary or a generator and maps the contents using a function.

eg: Fn.map(numbers, (integer i)->i*2)

Specifically, given:
Parameters:
container - A sequence, dictionary or generator.
func - A function or lambda from old value type to new value type.
Returns:
The container with all the values run through func.

mul

any static mul(any acc, any i)
Action for multiplying together the values in a sequence or generator of integer, float or decimal using accumulate or reduce.

eg: integer product := Fn.reduce(numbers, Fn.mul);
Parameters:
acc
i

negative

boolean static negative(any i)
A predicate which returns true if the argument is negative.
Parameters:
i

odd

boolean static odd(integer i)
A predicate which returns true if the argument is odd.
Parameters:
i

partial

com.apamax.functional.Partial static partial(any func, any args)
Partially execute a function, providing some arguments, to be later executed with the remaining arguments. Arguments must be provided left-to-right for the function call to be invoked. eg: Partial p := Fn.partial(concatFn, "Hello"); <string>p.exec(" world"); Partial objects can be passed to any of the other actions on Fn where an action would be expected.
Parameters:
func - A function (including an earlier partial()) to execute once all arguments are provided.
args - The arguments to store for later execution. May be a single argument, or a sequence of several arguments.

positive

boolean static positive(any i)
A predicate which returns true if the argument is positive (not including 0).
Parameters:
i

range

sequence<integer> static range(integer start, integer end, integer stride)
Returns a range of integers from start (inclusive) to end (exclusive), incrementing stride each time.
Parameters:
start
end
stride

reduce

any static reduce(any container, any func)
Takes either a sequence or a dictionary and accumulates all of the values using an accumulator function, returning the final result.

eg: Fn.reduce(numbers, (integer a, integer i)->a+i)

Specifically, given:
Parameters:
container - A sequence or dictionary.
func - An accumulator function or lambda.
Returns:
The final result of the accumulator function.

reduceFrom

any static reduceFrom(any accumulator, any container, any func)
Takes either a sequence or a dictionary and accumulates all of the values using an accumulator function, returning the final result.

eg: Fn.reduceFrom(42, numbers, (integer a, integer i)->a+i)

Specifically, given:
Parameters:
accumulator - initial value, of TYPEB
container - A sequence or dictionary.
func - An accumulator function or lambda.
Returns:
The final result of the accumulator function.

repeat

com.apamax.functional.Generator static repeat(any item)
Repeats the given element forever.
Parameters:
item - The item to return.
Returns:
A generator which returns item over and over again.

sequenceOf

any static sequenceOf(any item, integer n)
Returns a sequence containing the given item the given number of times.
Parameters:
item - The element to put in the sequence.
n - The number of times to repeat the element.
Returns:
A sequence<ITEMTYPE> with n items in it.

slice

any static slice(any container, integer start, integer end, integer stride)
Takes either a sequence or a generator and returns a given sub-range as a finite sequence. If it is passed a generator, it will invoke the generator sufficient times immediately to satisfy the slice.

eg: Fn.slice(numbers, 5, 20, 2)
Parameters:
container - A sequence<TYPE> or generator which produces TYPE.
start - The first item to return.
end - The last item to return (-1 = all, only permitted for sequences).
stride - The number of items to increment each time (1 = all).
Returns:
A sequence<TYPE> containing the selected values from container

sum

any static sum(any acc, any i)
Action for adding up a sequence or generator of integer, float or decimal using accumulate or reduce.

eg: integer sum := Fn.reduce(numbers, Fn.sum);
Parameters:
acc
i

whole

boolean static whole(any i)
A predicate which returns true if the argument is a whole number.
Parameters:
i