Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Latest commit

 

History

History
64 lines (51 loc) · 1.91 KB

cp.rx.go.md

File metadata and controls

64 lines (51 loc) · 1.91 KB

docs » cp.rx.go


Defines Statements to make processing of cp.rx.Observable values in ways that are more familiar to synchronous programmers.

A common activity is to perform some tasks, wait for the results and do some more work with those results.

Lets say you want to calculate the price of an item that is in US Dollars (USD) and output it in Australian Dollars (AUD). We have anItem that will return an Observable that fetches the item price, and an exchangeRate function that will fetch the current exchange rate for two currencies.

Using reactive operators, you could use the zip function to achieve this:

Observable.zip(
    anItem:priceInUSD(),
    exchangeRate("USD", "AUD")
)
:subscribe(function(price, rate)
    print "AUD Price: ", price * rate
end)

The final subscription will only be executed once both the priceInUSD() and exchangeRate(...) push a value. It will continue calling it while both keep producing values, but will complete if any of them complete.

Using the Given statement it would look like this:

Given(
   anItem:priceInUSD(),
   exchangeRate("USD", "AUD"),
)
:Now(function(price, rate)
    print "AUD Price: ", price * rate
end)

For more information on using and creating statements, see the Statements documentation.

Submodules

API Overview

API Documentation