Skip to content

Examples Observers

Luis Llamas edited this page Apr 25, 2019 · 11 revisions

★ = important

Do

#include "ReactiveArduinoLib.h"

auto observableInt = Reactive::FromProperty<int>();

void setup()
{
	Serial.begin(9600);
	while (!Serial) delay(1);

	Reactive::FromRange<int>(1, 10, 2)
	>> Reactive::Do<int>([](int x) { Serial.println(2 * x); });
}

void loop()
{
}

DoAndFinally ★

#include "ReactiveArduinoLib.h"

auto observableInt = Reactive::FromProperty<int>();

void setup()
{
	Serial.begin(9600);
	while (!Serial) delay(1);

	Reactive::FromRange<int>(1, 10, 2)
	>> Reactive::DoAndFinally<int>( [](int x) { Serial.println(2 * x); },
					[]() { Serial.println("No more items"); });
}

void loop()
{
}

Finally

#include "ReactiveArduinoLib.h"

auto observableInt = Reactive::FromProperty<int>();

void setup()
{
	Serial.begin(9600);
	while (!Serial) delay(1);

	Reactive::FromRange<int>(1, 10, 2)
	>> Reactive::Finally<int>([]() { Serial.println("No more items"); });
}

void loop()
{
}
Clone this wiki locally