Chris--A / PrintEx

An extension to the Arduino Print library, and much, much more...
GNU General Public License v3.0
61 stars 16 forks source link

Add ability to read a stream in a ranged loop #22

Open Chris--A opened 8 years ago

Chris--A commented 8 years ago

By adding in an iterator for stream reading, the two step process of checking for available data, and reading the character can become a single operation.

StreamEx s = Serial;

for( char c : s ){
  //got char 'c'
}

This would be the equivalent to:

  int current;
  while( (current = Serial.read()) != -1 ){
    //do something with current.
  }