Skip to content

Commit 682bf44

Browse files
committed
Added reduce example
1 parent e1fede6 commit 682bf44

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

examples/Reduce/Reduce.ino

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/***************************************************
2+
Copyright (c) 2019 Luis Llamas
3+
(www.luisllamas.es)
4+
5+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License
8+
****************************************************/
9+
10+
#include "ReactiveArduinoLib.h"
11+
using namespace Reactive;
12+
13+
int values[] = { 0, 1, 4, 6, 2, 5, 7, 3, 5, 8 };
14+
int valuesLength = sizeof(values) / sizeof(values[0]);
15+
16+
void setup()
17+
{
18+
Serial.begin(115200);
19+
while (!Serial) delay(1);
20+
}
21+
22+
// Start with a float value of 10.0 (optional) and add 1.5 times the (integer) value
23+
24+
void loop()
25+
{
26+
FromArray(values, valuesLength)
27+
.Reduce<float>([](float acc, int value) {
28+
return acc + value * 1.5f;
29+
}, 10.0f)
30+
.DoAndFinally(
31+
[](float x) { Serial.println(x); },
32+
[]() { Serial.println("No more items"); }
33+
);
34+
35+
delay(2000);
36+
}

0 commit comments

Comments
 (0)