Code coverage report for sc/classlib/Streams/ListPatterns.js

Statements: 100% (28 / 28)      Branches: 100% (2 / 2)      Functions: 100% (9 / 9)      Lines: 100% (28 / 28)      Ignored: none     

All files » sc/classlib/Streams/ » ListPatterns.js
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 591     1   1   1 1 1   1     46 45   1     1 1         1 1   1     44     1     76   76 76 76   76 77 77 240 240 240       76          
SCScript.install(function(sc) {
  "use strict";
 
  require("./Patterns");
 
  var $ = sc.lang.$;
 
  sc.lang.klass.define("ListPattern : Pattern", function(builder) {
    builder.addProperty("<>", "list");
    builder.addProperty("<>", "repeats");
 
    builder.addClassMethod("new", {
      args: "list; repeats=1"
    }, function($list, $repeats) {
      if ($list.size().__int__() > 0) {
        return this.__super__("new").list_($list).repeats_($repeats);
      }
      throw new Error("ListPattern (" + this.__className + ") requires a non-empty collection.");
    });
 
    builder.addMethod("copy", function() {
      return this.__super__("copy").list_(this._$list.copy());
    });
    // TODO: implements storeArgs
  });
 
  sc.lang.klass.define("Pseq : ListPattern", function(builder) {
    builder.addProperty("<>", "offset");
 
    builder.addClassMethod("new", {
      args: "list; repeats=1; offset=0"
    }, function($list, $repeats, $offset) {
      return this.__super__("new", [ $list, $repeats ]).offset_($offset);
    });
 
    builder.addMethod("embedInStream", {
      args: "inval"
    }, function($inval) {
      var $list, $offset, $repeats;
 
      $list    = this._$list;
      $offset  = this._$offset;
      $repeats = this._$repeats;
 
      $repeats.value($inval).do($.Func(function() {
        var $offsetValue = $offset.value($inval);
        return $list.size().do($.Func(function($_, $i) { // TODO: reverseDo?
          var $item  = $list.wrapAt($i.$("+", [ $offsetValue ]));
          $inval = $item.embedInStream($inval);
          return $inval;
        }));
      }));
 
      return $inval;
    });
    // TODO: implements storeArgs
  });
});