Reaxive.Sync
Implements the Reaxive Extensions as synchronous function composition similar to
Elixir’s Enum
and Stream
libraries, but adheres to the Observable
protocol.
Design Idea
The operators are used in two phases. First, they are composed to a single function,
which represents the sequence of the operators together with their initial accumulator
list. The list might be empty, if no accumulator is used by the given operators (e.g.
if using map
and filter
only).
The second phase is the execution phase. Similar to transducers, the composed operators
make no assumptions how the calculated values are used and how the accumulators are stored
between two operator evaluations. This could be done as inside Rx.Impl
, but other
implementations are possible. The result, i.e. which send to the consumers, is always the head
of the accumulator, unless the reason tag is :ignore
or :halt
.
Summary
all(pred) | the |
any(pred) | the |
as_text() | |
default_behavior(accu \\ nil, list) | This macro encodes the default behavior for reduction functions, which is capable of
ignoring values, of continuing work with |
distinct(empty_set) | a filter passing through only distinct values |
distinct_until_changed() | a filter for repeating values, i.e. only changed values can pass |
drop(n) | Reducer function for |
drop_while(pred) | Reducer for |
emit(v, acc, new_a, new_acc) | |
emit_and_halt(acc, new_a, new_acc) | |
error(error, acc, new_a, new_acc) | |
filter(pred) | Reducer function for filter |
flat_mapper(flatter, map_fun) | This is the mapping part of |
flatter() | The |
full_behavior(accu \\ nil, next_fun, comp_fun, error_fun) | This function takes an initial accumulator and three step functions. The step functions have as first parameter the current value, followed by the list of next accumulators, the current accumulator, and the list of future accumulators. The three functions handle the situation of the next value, of completion of the stream and of the error situation |
halt(acc, new_a, new_acc) | |
ignore(v, acc, new_a, new_acc) | |
map(fun) | Reducer function for map |
merge(n) | Reducer for merging |
product() | Returns the product of input events as sequence with exactly one event |
reduce(accu \\ nil, next_fun) | Takes a next function and an accu and applies it to each value. Emits only the accumulator after the source sequence is finished |
simple_reduce(accu, red_fun) | Reducer for a simple reducer |
sum() | Returns the sum of input events as sequence with exactly one event |
take(n) | Reducer function for |
take_while(pred) | Reducer for |
Types
reason_t :: :cont | :ignore | :halt | :error | :on_completed | :on_next | :on_error
acc_t :: [any]
step_fun_t :: (any, acc_t, any, acc_t -> reduce_t)
reducer_fun_t :: (reduce_t -> any)
transform_t :: {reducer_fun_t, any}
Functions
Specs:
- all((any -> boolean)) :: transform_t
the all
reducer works with a short-cut
Specs:
- any((any -> boolean)) :: transform_t
the any
reducer works with a short-cut
Specs:
- as_text :: transform_t
Specs:
- distinct(Set.t) :: transform_t
a filter passing through only distinct values
Specs:
- distinct_until_changed :: transform_t
a filter for repeating values, i.e. only changed values can pass
Reducer function for drop
Specs:
- drop_while((any -> boolean)) :: transform_t
Reducer for drop_while
Specs:
- filter((any -> boolean)) :: transform_t
Reducer function for filter
Specs:
- flat_mapper(Reaxive.Rx.Impl.t, (any -> Observable.t)) :: transform_t
This is the mapping part of flat_map
. It gets a flatter rx process
as parameter. For each event v
, it starts a new mapping process by
applying map_fun
to v
. The flatter
subscribes to the new mapping
process to receive the newly produced events.
Specs:
- flatter :: transform_t
The flatter
function implements a behaivour that emits all values and
ignores all on_completed
messages. If the flatter
has to stop, this has
to be determined by Rx.Impl
, i.e. stop if no sources are available or
if no subscribers are available.
Specs:
- full_behavior(any, step_fun_t, step_fun_t, step_fun_t) :: transform_t
This function takes an initial accumulator and three step functions. The step functions have as first parameter the current value, followed by the list of next accumulators, the current accumulator, and the list of future accumulators. The three functions handle the situation of the next value, of completion of the stream and of the error situation.
Handling the ignore
case is part of full_behavior
and cannot be handled by the step functions.
It is best to use the halt
, emit
, ignore
and error
macros to produce proper return
values of the three step functions.
Specs:
- map((any -> any)) :: transform_t
Reducer function for map.
Reducer for merging n
streams
Returns the product of input events as sequence with exactly one event.
Specs:
- reduce(any, step_fun_t) :: transform_t
Takes a next function and an accu and applies it to each value. Emits only the accumulator after the source sequence is finished.
Reducer for a simple reducer
Returns the sum of input events as sequence with exactly one event.
Reducer function for take
Specs:
- take_while((any -> boolean)) :: transform_t
Reducer for take_while
Macros
This macro encodes the default behavior for reduction functions, which is capable of
ignoring values, of continuing work with :on_next
, and of piping values for :on_completed
and :on_error
.
You must provide the implementation for the :on_next
branch. Implicit parameters are the
value v
and the accumulator list acc
, the current accumulator a
and the new accumulator
new_acc
.