Skip to content

Examples Operators

Luis Llamas edited this page Aug 26, 2019 · 8 revisions

★ = important

Where ★

#include "ReactiveArduinoLib.h"

int values[] = { 0, 1, 1, 2, 1, 5, 4 }; 
size_t valuesLength = sizeof(values) / sizeof(values[0]);

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

	Reactive::FromArray(values, valuesLength)
	.Where([](int x) {return x >= 2; })
	.ToSerial();
}

void loop()
{
}

Distinct ★

#include "ReactiveArduinoLib.h"

int values[] = { 0, 1, 1, 2, 1, 5, 4 };
size_t valuesLength = sizeof(values) / sizeof(values[0]);

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

	Reactive::FromArray(values, valuesLength)
	.Distinct()
	.ToSerial();
}

void loop()
{
}

If

#include "ReactiveArduinoLib.h"

int values[] = { 0, 1, 1, 2, 1, 5, 4 };
size_t valuesLength = sizeof(values) / sizeof(values[0]);

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

	Reactive::FromArray(values, valuesLength)
	.If([](int x) { return x > 2; },
		[](int x) {Serial.println(10 * x); })
	.If([](int x) { return x <= 2; },
		[](int x) {Serial.println(5 * x); })
	.DoNothing();
}

void loop()
{
}

ForEach

#include "ReactiveArduinoLib.h"

int values[] = { 0, 1, 1, 2, 1, 5, 4 }; 
size_t valuesLength = sizeof(values) / sizeof(values[0]);

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

	Reactive::FromArray(values, valuesLength)
	.ForEach([](int x) {Serial.println(x); })
	.DoNothing();
}

void loop()
{
}

Repeat

#include "ReactiveArduinoLib.h"

int values[] = { 0, 1, 1, 2, 1, 5, 4 }; 
size_t valuesLength = sizeof(values) / sizeof(values[0]);

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

	Reactive::FromArray(values, valuesLength)
	.Repeat(3)
	.ToSerial();
}

void loop()
{
}
Clone this wiki locally