all files / lib/stream/ arraystream.js

100% Statements 11/11
100% Branches 0/0
100% Functions 5/5
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38                              11×         11×       10×     11×      
/*
 * Parsec
 * https://github.com/d-plaindoux/parsec
 *
 * Copyright (c) 2016 Didier Plaindoux
 * Licensed under the LGPL2 license.
 */
 
 module.exports = (function() {
     
     'use strict';
     
     var stream = require('./stream.js');
               
     /**
      * Array stream class
      */
     function ArrayStream(source) {
         this.source = source;
     }
 
     ArrayStream.prototype = stream();
     
     // ArrayStream 'a => unit -> boolean
     ArrayStream.prototype.endOfStream = function(index) {
         return this.source.length <= index;
     };
     
     // ArrayStream 'a => number -> 'a <+> error
     ArrayStream.prototype.unsafeGet = function(index) {
         return this.source[index];
     };
 
     return function(source) {
         return new ArrayStream(source);
     };
          
 }());