Internationalisation
Bundled Plugins API
Observable
Observables push values to Observers.

API Overview

API Documentation

Functions

is

Signature
cp.rx.Observable.is(thing) -> boolean
Type
Function
Description
Checks if the thing is an instance of Observable.
Parameters
  • thing - The thing to check.
Returns
  • true if the thing is an Observable.

Constructors

create

Signature
cp.rx.Observable.create(onSubscription) -> cp.rx.Observable
Type
Constructor
Description
Creates a new Observable.
Parameters
  • onSubscription - The reference function that produces values.
Returns
  • The new Observable.

defer

Signature
cp.rx.Observable.defer(fn) -> cp.rx.Observable
Type
Constructor
Description
Creates an Observable that executes the function to create a new Observable each time an Observer subscribes.
Parameters
  • fn - A function that returns an Observable.
Returns
  • The new Observable.

empty

Signature
cp.rx.Observable.empty() -> cp.rx.Observable
Type
Constructor
Description
Returns an Observable that immediately completes without producing a value.
Parameters
  • None
Returns
  • The new Observable.
Signature
cp.rx.Observable.firstEmitting(...) -> cp.rx.Observer
Type
Constructor
Description
Given a set of Observables, produces values from only the first one to produce a value or complete.
Parameters
Returns
  • The new Observable.
Signature
cp.rx.Observable.fromCoroutine(fn, scheduler) -> cp.rx.Observable
Type
Constructor
Description
Creates an Observable that produces values when the specified coroutine yields.
Parameters
  • fn - A coroutine or function to use to generate values. Note that if a coroutine is used, the values it yields will be shared by all subscribed Observers (influenced by the Scheduler), whereas a new coroutine will be created for each Observer when a function is used.
Returns
  • The new Observable.
Signature
cp.rx.Observable.fromFileByLine(filename) -> cp.rx.Observable
Type
Constructor
Description
Creates an Observable that produces values from a file, line by line.
Parameters
  • filename - The name of the file used to create the Observable.
Returns
  • The new Observable.

fromRange

Signature
cp.rx.Observable.fromRange(initial[, limit[, step]]) -> cp.rx.Observable
Type
Constructor
Description
Creates an Observable that produces a range of values in a manner similar to a Lua for loop.
Parameters
  • initial - The first value of the range, or the upper limit if no other arguments are specified.
  • limit - The second value of the range. Defaults to no limit.
  • step - An amount to increment the value by each iteration. Defaults to 1.
Returns
  • The new Observable.

fromTable

Signature
cp.rx.Observable.fromTable(t, iterator, keys) -> cp.rx.Observable
Type
Constructor
Description
Creates an Observable that produces values from a table.
Parameters
  • t - The table used to create the Observable.
  • iterator - An iterator used to iterate the table, e.g. pairs or ipairs. Defaults to pairs.
  • keys - If true, also emit the keys of the table. Defaults to false.
Returns
  • The new Observable.

never

Signature
cp.rx.Observable.never() -> cp.rx.Observable
Type
Constructor
Description
Returns an Observable that never produces values and never completes.
Parameters
  • None
Returns
  • The new Observable.

of

Signature
cp.rx.Observable.of(...) -> cp.rx.Observable
Type
Constructor
Description
Creates an Observable that produces a set of values.
Parameters
  • ... - The list of values to send as individual onNext values.
Returns
  • The new Observable.

replicate

Signature
cp.rx.Observable.replicate(value[, count]) -> cp.rx.Observable
Type
Constructor
Description
Creates an Observable that repeats a value a specified number of times.
Parameters
  • value - The value to repeat.
  • count - The number of times to repeat the value. If left unspecified, the value is repeated an infinite number of times.
Returns
  • The new Observable.

throw

Signature
cp.rx.Observable.throw(message, ...) -> cp.rx.Observable
Type
Constructor
Description
Returns an Observable that immediately produces an error.
Parameters
  • message - The message to send.
  • ... - The additional values to apply to the message, using string.format syntax.
Returns
  • The new Observable.

zip

Signature
cp.rx.Observable.zip(...) -> cp.rx.Observable
Type
Constructor
Description
Returns an Observable that merges the values produced by the source Observables by grouping them
Parameters
  • ... - The Observables to zip.
Returns
  • The new Observable.

Methods

all

Signature
cp.rx.Observable:all(predicate) -> cp.rx.Observable
Type
Method
Description
Determine whether all items emitted by an Observable meet some criteria.
Parameters
  • predicate - The predicate used to evaluate objects. Defaults to the identity.
Returns
  • A new Observable.

average

Signature
cp.rx.Observable:average() -> cp.rx.Observable
Type
Method
Description
Returns an Observable that produces the average of all values produced by the original.
Returns
  • The new Observable.

buffer

Signature
cp.rx.Observable:buffer(size) -> cp.rx.Observable
Type
Method
Description
Returns an Observable that buffers values from the original and produces them as multiple values.
Parameters
  • size - The size of the buffer.
Returns
  • The new Observable.

catch

Signature
cp.rx.Observable:catch(handler) -> cp.rx.Observable
Type
Method
Description
Returns an Observable that intercepts any errors from the previous and replace them with values
Parameters
  • handler - An Observable or a function that returns an Observable to replace the source Observable in the event of an error.
Returns
  • The new Observable.
Signature
cp.rx.Observable:combineLatest(...) -> cp.rx.Observable
Type
Method
Description
Returns a new Observable that runs a combinator function on the most recent values from a set
Parameters
  • ... - One or more Observables to combine.
  • combinator - A function that combines the latest result from each Observable and returns a single value.
Returns
  • The new Observable.

compact

Signature
cp.rx.Observable:compact() -> cp.rx.Observable
Type
Method
Description
Returns a new Observable that produces the values of the first with falsy values removed.
Returns
  • The new Observable.

concat

Signature
cp.rx.Observable:concat(...) -> cp.rx.Observable
Type
Method
Description
Returns a new Observable that produces the values produced by all the specified Observables in
Parameters
  • ... - The list of Observables to concatenate.
Returns
  • The new Observable.

contains

Signature
cp.rx.Observable:contains(value) -> cp.rx.Observable
Type
Method
Description
Returns a new Observable that produces a single boolean value representing whether or not the
Parameters
  • value - The value to search for. == is used for equality testing.
Returns
  • The new Observable.

count

Signature
cp.rx.Observable:count([predicate]) -> cp.rx.Observable
Type
Method
Description
Returns an Observable that produces a single value representing the number of values produced
Parameters
  • predicate - The predicate function used to match values.
Returns
  • The new Observable.

debounce

Signature
cp.rx.Observable:debounce(time[, scheduler]) -> cp.rx.Observable
Type
Method
Description
Returns an Observable that mirrors the source Observable, except that it drops items emitted by the source
Parameters
  • time - The number of milliseconds.
  • scheduler - The scheduler. Uses the defaultScheduler by default.
Returns
  • The new Observable.
Signature
cp.rx.Observable:defaultIfEmpty(...)
Type
Method
Description
Returns a new Observable that produces a default set of items if the source Observable produces
Returns
  • The new Observable.

delay

Signature
cp.rx.Observable:delay(time, scheduler) -> cp.rx.Observable
Type
Method
Description
Returns a new Observable that produces the values of the original delayed by a time period.
Parameters
  • time - An amount in milliseconds to delay by, or a function which returns this value.
  • scheduler - The Scheduler to run the Observable on.
Returns
  • The new Observable.

distinct

Signature
cp.rx.Observable:distinct() -> cp.rx.Observable
Type
Method
Description
Returns a new Observable that produces the values from the original with duplicates removed.
Returns
  • The new Observable.
Signature
cp.rx.Observable:distinctUntilChanged([comparator]) -> cp.rx.Observable
Type
Method
Description
Returns an Observable that only produces values from the original if they are different from
Parameters
  • comparator - A function used to compare 2 values. If unspecified, == is used.
Returns
  • The new Observable

dump

Signature
cp.rx.Observable:dump(name, formatter)
Type
Method
Description
Subscribes to this Observable and prints values it produces.
Parameters
  • name - Prefixes the printed messages with a name.
  • formatter - A function that formats one or more values to be printed. Defaults to tostring.
Returns

elementAt

Signature
cp.rx.Observable:elementAt(index) -> cp.rx.Observable
Type
Method
Description
Returns an Observable that produces the nth element produced by the source Observable.
Parameters
  • index - The index of the item, with an index of 1 representing the first.
Returns
  • The new Observable.

filter

Signature
cp.rx.Observable:filter(predicate) -> cp.rx.Observable
Type
Method
Description
Returns a new Observable that only produces values of the first that satisfy a predicate.
Parameters
  • predicate - The predicate function used to filter values.
Returns
  • The new Observable.

finalize

Signature
cp.rx.Observable:finalize(handler) -> cp.rx.Observable
Type
Method
Description
Returns an Observable that mirrors the source Observable, but will call a specified function
Parameters
  • handler - The handler function to call when onError/onCompleted occurs.
Returns
  • The new Observable.

find

Signature
cp.rx.Observable:find(predicate) -> cp.rx.Observable
Type
Method
Description
Returns a new Observable that produces the first value of the original that satisfies a
Parameters
  • predicate - The predicate function used to find a value.
Returns
  • The new Observable.

first

Signature
cp.rx.Observable:first() -> cp.rx.Observable
Type
Method
Description
Returns a new Observable that only produces the first result of the original.
Returns
  • The new Observable.

flatMap

Signature
cp.rx.Observable:flatMap(callback) -> cp.rx.Observable
Type
Method
Description
Returns a new Observable that transform the items emitted by an Observable into Observables,
Parameters
  • callback - The function to transform values from the original Observable.
Returns
  • The new Observable.
Signature
cp.rx.Observable:flatMapLatest([callback]) -> cp.rx.Observable
Type
Method
Description
Returns a new Observable that uses a callback to create Observables from the values produced by
Parameters
@arg {function=identity} callback - The function used to convert values to Observables. Defaults to the identity function.
Returns
  • The new Observable.

flatten

Signature
cp.rx.Observable:flatten()
Type
Method
Description
Returns a new Observable that subscribes to the Observables produced by the original and
Returns
  • The new Observable.
Signature
cp.rx.Observable:ignoreElements() -> cp.rx.Observable
Type
Method
Description
Returns an Observable that terminates when the source terminates but does not produce any
Returns
  • The new Observable.

last

Signature
cp.rx.Observable:last() -> cp.rx.Observable
Type
Method
Description
Returns a new Observable that only produces the last result of the original.
Returns
  • The new Observable.

map

Signature
cp.rx.Observable:map(callback) -> cp.rx.Observable
Type
Method
Description
Returns a new Observable that produces the values of the original transformed by a function.
Parameters
  • callback - The function to transform values from the original Observable.