observables v0.1.9 Observables.Obs View Source

Link to this section Summary

Functions

Periodically gather items emitted by an Observable into bundles of size size and emit these bundles rather than emitting the items one at a time

Chunks items produces by the observable together bounded in time. As soon as the set delay has been passed, the observable emits an enumerable with the elements gathered up to that point. Does not emit the empty list

Given two observables, merges them together and always merges the last result of on of both, and reuses the last value from the other

Given two observables, merges them together and always merges the last result of on of both, and reuses the last value from the other

Filters out values that have already been produced by any given observable. Uses the default == function if none is given

Same as map, but returns the original value. Typically used for side effects

Filters out the values that do not satisfy the given predicate

Takes an enumerable and turns it into an observable that produces a value for each value of the enumerable. If the enum is consumed, returns done

from_pid/1 can be considered to be a subject. Any process that implements the GenObservable interface can be used a subject, actually. Example: Spawn a subject using the Subject module. {:ok, pid1} = GenObservable.spawn_supervised(Subject, 0)

Same as the print/1 function, but uses inspect to print instead of puts

Applies a given function to each value produces by the dependency observable

Combine two observables into a single observable that will emit the events produced by the inputs

Prints out the values produces by this observable. Keep in mind that this only works for values that are actually printable. If not sure, use inspect/1 instead

Range creates an observable that will start at the given integer and run until the last integer. If no second argument is given, the stream is infinite. One can use :infinity as the end for an infinite stream (see: https://elixirforum.com/t/infinity-in-elixir-erlang/7396)

repeat takes a function as argument and an optional interval. The function will be repeatedly executed, and the result will be emitted as an event

Applies a given procedure to an observable’s value, and its previous result. Works in the same way as the Enum.scan function

Prepends any observable with a list of values provided here in the form of a list

Convert an Observable that emits Observables into a single Observable that emits the items emitted by the most-recently-emitted of those Observables

Takes the n first element of the observable, and then stops

Combine the emissions of multiple Observables together via a specified function and emit single items for each combination based on the results of this function

Link to this section Functions

Periodically gather items emitted by an Observable into bundles of size size and emit these bundles rather than emitting the items one at a time.

Source: http://reactivex.io/documentation/operators/buffer.html

Chunks items produces by the observable together bounded in time. As soon as the set delay has been passed, the observable emits an enumerable with the elements gathered up to that point. Does not emit the empty list.

Works in the same vein as the buffer observable, but that one is bound by number, and not by time.

Source: http://reactivex.io/documentation/operators/buffer.html

Link to this function combinelatest(l, r, opts \\ [left: nil, right: nil]) View Source

Given two observables, merges them together and always merges the last result of on of both, and reuses the last value from the other.

E.g. 1 -> 2 ———> 3 A ——-> B ———> C

1A —> 2A -> 2B -> 3B -> 3C

More information: http://reactivex.io/documentation/operators/combinelatest.html

Link to this function combinelatestsilent(l, r, opts \\ [left: nil, right: nil, silent: :right]) View Source

Given two observables, merges them together and always merges the last result of on of both, and reuses the last value from the other.

The nuance with combinelatest here is that one of both observables will not trigger an update, but will update silently.

E.g. 1 -> 2 ———> 3 A ——-> B ———> C

1A —> 2A ——> 3B

More information: http://reactivex.io/documentation/operators/combinelatest.html

Link to this function distinct(arg, f \\ fn x, y -> x == y end) View Source

Filters out values that have already been produced by any given observable. Uses the default == function if none is given.

The expected function should take 2 arguments, and return a boolean indication the equality.

More information: http://reactivex.io/documentation/operators/distinct.html

Same as map, but returns the original value. Typically used for side effects.

More information: http://reactivex.io/documentation/operators/subscribe.html

Filters out the values that do not satisfy the given predicate.

The expection function should take 1 arguments and return a boolean value. True if the value should be produced, false if the value should be discarded.

More information: http://reactivex.io/documentation/operators/filter.html

Link to this function from_enum(coll, delay \\ 1000) View Source

Takes an enumerable and turns it into an observable that produces a value for each value of the enumerable. If the enum is consumed, returns done.

More information: http://reactivex.io/documentation/operators/from.html

from_pid/1 can be considered to be a subject. Any process that implements the GenObservable interface can be used a subject, actually. Example: Spawn a subject using the Subject module. {:ok, pid1} = GenObservable.spawn_supervised(Subject, 0)

Print out each value that the subject produces. Obs.from_pid(pid1) |> Obs.print()

Send an event to the subject. GenObservable.send_event(pid1, :value)

More information: http://reactivex.io/documentation/subject.html

Same as the print/1 function, but uses inspect to print instead of puts.

Applies a given function to each value produces by the dependency observable.

More information: http://reactivex.io/documentation/operators/map.html

Combine two observables into a single observable that will emit the events produced by the inputs.

More information: http://reactivex.io/documentation/operators/merge.html

Prints out the values produces by this observable. Keep in mind that this only works for values that are actually printable. If not sure, use inspect/1 instead.

Link to this function range(first, last, delay \\ 1000) View Source

Range creates an observable that will start at the given integer and run until the last integer. If no second argument is given, the stream is infinite. One can use :infinity as the end for an infinite stream (see: https://elixirforum.com/t/infinity-in-elixir-erlang/7396)

More information: http://reactivex.io/documentation/operators/range.html

repeat takes a function as argument and an optional interval. The function will be repeatedly executed, and the result will be emitted as an event.

More information: http://reactivex.io/documentation/operators/repeat.html

Link to this function scan(arg, f, default \\ nil) View Source

Applies a given procedure to an observable’s value, and its previous result. Works in the same way as the Enum.scan function:

Enum.scan(1..10, fn(x,y) -> x + y end) => [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]

More information: http://reactivex.io/documentation/operators/scan.html

Link to this function starts_with(arg, start_vs) View Source

Prepends any observable with a list of values provided here in the form of a list.

More information: http://reactivex.io/documentation/operators/startwith.html

Convert an Observable that emits Observables into a single Observable that emits the items emitted by the most-recently-emitted of those Observables.

More information: http://reactivex.io/documentation/operators/switch.html

Takes the n first element of the observable, and then stops.

More information: http://reactivex.io/documentation/operators/take.html

Combine the emissions of multiple Observables together via a specified function and emit single items for each combination based on the results of this function.

More information: http://reactivex.io/documentation/operators/zip.html