All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ceylon.language.ChainedIterator.ceylon Maven / Gradle / Ivy

There is a newer version: 1.3.3
Show newest version
"An [[Iterator]] that returns the elements of two
 [[Iterable]]s, as if they were chained together."
see (`function Iterable.chain`)
by ("Enrique Zamudio")
tagged("Streams")
class ChainedIterator
		        ({Element*} first, {Other*} second) 
        satisfies Iterator {
    
    variable Iterator iter = first.iterator();
    variable value more = true;
    
    shared actual Element|Other|Finished next() {
        value element = iter.next();
        if (more && element is Finished) {
            iter = second.iterator();
            more = false;
            return iter.next();
        }
        else {
            return element;
        }
    }
    
    string => "``first``.chain(``second``).iterator()";
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy