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.

Source

Summary

all(pred)

the all reducer works with a short-cut

any(pred)

the any reducer works with a short-cut

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 :on_next, and of piping values for :on_completed and :on_error

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

drop_while(pred)

Reducer for drop_while

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 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

flatter()

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

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 n streams

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

take_while(pred)

Reducer for take_while

Types

reason_t :: :cont | :ignore | :halt | :error | :on_completed | :on_next | :on_error

acc_t :: [any]

tagged_t :: {reason_t, any}

step_fun_t :: (any, acc_t, any, acc_t -> reduce_t)

reducer_fun_t :: (reduce_t -> any)

Functions

all(pred)

Specs:

the all reducer works with a short-cut

Source
any(pred)

Specs:

the any reducer works with a short-cut

Source
as_text()

Specs:

Source
distinct(empty_set)

Specs:

a filter passing through only distinct values

Source
distinct_until_changed()

Specs:

a filter for repeating values, i.e. only changed values can pass

Source
drop(n)

Reducer function for drop

Source
drop_while(pred)

Specs:

Reducer for drop_while

Source
filter(pred)

Specs:

Reducer function for filter

Source
flat_mapper(flatter, map_fun)

Specs:

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.

Source
flatter()

Specs:

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.

Source
full_behavior(accu \\ nil, next_fun, comp_fun, error_fun)

Specs:

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.

Source
map(fun)

Specs:

Reducer function for map.

Source
merge(n)

Reducer for merging n streams

Source
product()

Returns the product of input events as sequence with exactly one event.

Source
reduce(accu \\ nil, next_fun)

Specs:

Takes a next function and an accu and applies it to each value. Emits only the accumulator after the source sequence is finished.

Source
simple_reduce(accu, red_fun)

Reducer for a simple reducer

Source
sum()

Returns the sum of input events as sequence with exactly one event.

Source
take(n)

Reducer function for take

Source
take_while(pred)

Specs:

Reducer for take_while

Source

Macros

default_behavior(accu \\ nil, list)

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.

Source
emit(v, acc, new_a, new_acc)
Source
emit_and_halt(acc, new_a, new_acc)
Source
error(error, acc, new_a, new_acc)
Source
halt(acc, new_a, new_acc)
Source
ignore(v, acc, new_a, new_acc)
Source