Implementation of a simple Stream in javascript