docs: function loopfn(name, dselect, inner, sorter, filter){
      return function(ctxt){
        var a = dselect(ctxt),
          old = ctxt[name],
          temp = { items : a },
          filtered = 0,
          length,
          strs = [],
          buildArg = function(idx, temp, ftr, len){
            ctxt.pos = temp.pos = idx;
            ctxt.item = temp.item = a[ idx ];
            ctxt.items = a;
            //if array, set a length property - filtered items
            typeof len !== 'undefined' &&  (ctxt.length = len);
            //if filter directive
            if(typeof ftr === 'function' && ftr(ctxt) === false){
              filtered++;
              return;
            }
            strs.push( inner.call(temp, ctxt ) );
          };
        ctxt[name] = temp;
        if( isArray(a) ){
          length = a.length || 0;
          // if sort directive
          if(typeof sorter === 'function'){
            a.sort(sorter);
          }
          //loop on array
          for(var i = 0, ii = length; i < ii; i++){
            buildArg(i, temp, filter, length - filtered);
          }
        }else{
          if(a && typeof sorter !== 'undefined'){
            error('sort is only available on arrays, not objects');
          }
          //loop on collections
          for(var prop in a){
            a.hasOwnProperty( prop ) && buildArg(prop, temp, filter);
          }
        }
  
        typeof old !== 'undefined' ? ctxt[name] = old : delete ctxt[name];
        return strs.join('');
      };
    }