VimUnDo=&Zrm-輆{'.9999PA4_PAvar Name = require('name')5_PAvar Name = require("name')5_P Avar core = require('./core'),5_P Avar core = require("./core'),5_PA 'use strict';5_ PA "use strict';5_ P Avar queued = Name()5_  P Avar queued = ""5_ P Avar queued = "queued"5_ P Avar queued = "queued" 5_ P Avar queued = "queued@" 5_ P Avar input = Name()5_  P Avar input = ""5_  P Avar input = "input@"5_ P Avar forward = Name()5_ P Avar forward = ""5_ P Avar forward = "forward"5_ P Avar forward = "forward@"5_P Avar state = Name()5_ P Avar state = ""5_P Avar state = "state@"5_Pvar Name = require("name")5_PA@5_PAvar convert = require()5_PAvar convert = require("")5_P B A5_P Bvar accumulate = require()5_P  Bvar accumulate = require("")5_ P  var core = require("./core"),5_ P  8 convert = core.convert, accumulate = core.accumulate5_ PI'/* vim:set ts=2 sw=2 sts=2 expandtab */5_! PIM/*jshint asi: true undef: true es5: true node: true browser: true devel: true5_ "! PI9 forin: true latedef: false globalstrict: true */5_!#"PI5_"$#PB=<5_#%$PB=var reducible = require()5_$&%PB=var reducible = require("")5_%'&%PBR%'> %'=5_&('&PBV%'> var self = reducible()5_')(& PBX%'>" var self = reducible(function())5_(*)&"PBX%'># var self = reducible(function( ))5_)+*&#PBY%'>% var self = reducible(function( ){})5_*,+&!PBZ%'>! var self = reducible(function()5_+-,&#PBZ%(>$ var self = reducible(function() {}5_,.-'PB[&(? }5_-/.& PB_%'?# var self = reducible(function() {5_.0/&,PBg&(@ &(?5_/10& PBt%'@0 var self = reducible(function(next, initial) {5_021%PBw$%/ var self = convert(source, buffer.accumulate)5_132&PBy%'? isDrained()5_243&4<vPB%0? isDrained(buffer)5_354'=EvPB&(HH if (isDrained(buffer)) return accumulate(buffer[input], next, initial)5_465'-=EvPB&(HJ if (isDrained(buffer)) return accumulate(buffer[input], next, initial)5_576'6=EvPB&(HF if (isDrained(buffer)) return reduce(buffer[input], next, initial)5_687'0=EvPB&(HE if (isDrained(buffer)) return reduce(buffer[input, next, initial)5_798=EvPBIH5_8:9>FvPBIvar reduce = require()5_9;:>FvPBIvar reduce = require("")5_:<;)>FvPB(*IM // Otherwise, drain the buffer, passing items to the accumulating function.5_;=<*>FvPB)+I. buffer[state] = drain(buffer, next, initial)5_<>=+>FvPB*,I/ // Overshadow forward function, insuring that5_=?>,>FvPB+-IK // future values are not buffered, and are instead passed directly to the5_>@?->FvPB,.I // accumulation function.5_?A@.>FvPB-/I buffer[forward] = next5_@BA/>FvPB.0I return buffer5_ACB0>FvPB/05_BDC0=EvPB02H5_CED2>FvPB13I self[state] = null5_DFE2 >FvPB13I function[state] = null5_EGF3>FvPB24I self[input] = source5_FHG >FvPB  var input = "input@" + module.id5_GIH'.=EvPB&(H> if (isDrained(buffer)) return reduce(input, next, initial)5_HJI% =EvPC  $&H2 var buffer = reducible(function(next, initial) {5_IKJ1=EvPC02H buffer[state] = null5_JLK) =EvPC(*H0 buffer[state] = drain(buffer, next, initial)5_KML) =EvPC$(*H0 values[state] = drain(buffer, next, initial)5_LNM) =EvPC&(*H0 values[state] = drain(values, next, initial)5_MON- =EvPC*,.H buffer[forward] = next5_NPO) =EvPC/ (*H/ values[state] = drain(value, next, initial)5_OQP'=EvPC2 &(H? if (isDrained(buffer)) return reduce(source, next, initial)5_PRQ=EvPC@IH5_QSR>FvPCDIfunction Buffer()5_RTS>FvPCDIfunction Buffer() {}5_SUT?GvPCIK J5_TVU@HvPCQK5_UWVAIvPCYM L5_VXWBJvPCgNM5_WYX%CKvPCoN%Buffer.prototype.forward = function()5_XZY'CKvPCoN(Buffer.prototype.forward = function() {}5_Y[Z#DLvPCyO'Buffer.prototype.forward = function() {5_Z\[<<vPCP O5_[]\==vPCP this.queued.push()5_\^],==vPC P/Buffer.prototype.forward = function forward() {5_]_^==vPCQP5_^`_>>vPCQaccumulate.default()5__b`>>vPCQaccumulate.defer)5_`cab>>vPCQaccumulate.define)5_bdc>>vPCQaccumulate.define()5_ced$>>vPCQ%accumulate.define(Buffer, function())5_dfe&>>vPC Q(accumulate.define(Buffer, function() {})5_egfvPC)Qaccumulate.define(Buffer, )R&accumulate.define(Buffer, function() {})5_fhgvPC\ [5_gihvPC\ this.queued = []5_hji vPC\ this[queued = []5_ikjvPC\ this.input = 5_jlk vPC\ this[input = 5_kmlvPC\ this[input] = 5_lnmvPC\ this.state = null5_mon vPC\ this[state = null5_npo vPC ] \5_oqp   vPC ]var input = ""5_prq   vPC  ]var input = "input@"5_qsr   vPD ^ ]5_rts##vPD ` function 5_sut ##vPD ` function 5_tvu##vPD `function buffer()5_uwv##vPD `function buffer(input)5_vxw##vPD `function buffer(input) {}5_wyx$$vPDb a5_xzy%%vPDb return reducible()5_y{z%%vPDb return reducible(function())5_z|{%%vPDb! return reducible(function() {})5_{}|&&vPDc return reducible(function() {5_|~}(&&vPDc5_}~''vPE e d5_~((vPEf e5_ ))vPE var buffered = intof var buffered = []f reduce()5_((vPE"e var buffered = into()5_((vPE)e5_ ((vPE-e reduces()5_ ((vPE6 f e5_ ))vPE; fvar into = required()5_ ))vPE< fvar into = required("")5_ ))vPEBf! reduces(input, next, initial)5_))vPEDf, return reducible(function(next, initial) {5_))vPEYf var buffered = into(input)5_))vPEag f5_ **vPEeg reduce()5_**vPEhg reduce(input, function())5_**vPEhg reduce(input, function() {})5_++vPEzh })5_++vPEh reduce(input, function() {5_++vPEh reductions(input, function() {5_++vPEh- var buffer = reductions(input, function() {}, )h }, )5_***vPEg1 var buffer = reductions(input, function() {}, )5_**vPEhg5_++vPEhfunction identity()5_++vPEhfunction identity() {}5_,,vPEifunction identity() {5_,,vPEifunction identity(vaule) {5_,,vPEifunction identity(value) {5_,,vPE}5_0++vPEh3 var buffer = reductions(input, function(st) {}, )5_+++vPEh, var buffer = reductions(input, identity, )5_++vPE* var buffer = reductions(input, identity)5_**vPEh g5_ ++vPEh reduce()5_++vPEh reduce(input, function())5_++vPEh reduce(input, function() {})5_,,vPEi reduce(input, function() {5_,,vPEi accumulate(input, function() {5_#,,vPEi& accumulate(input, function(values) {5_%,,vPEi% accumulate(input, function(value) {5_2,,vPFi3 accumulate(input, function(value) { buffer.push()5_,,vPFi8 accumulate(input, function(value) { buffer.push(input)})i })5_,++vPF$h; accumulate(input, function(value) { buffer.push(input) })5_-++vPF&h< accumulate(input, function(value) { buffere.push(input) })5_<++vPF6h= accumulate(input, function(value) { buffered.push(input) })5_++vPF:ih5_,,vPF;fu5_++vPF<)function identity(value) { return value }5_**vPF=hg5_++vPFFhfunction push()5_++vPFNhfunction push(vlaue, buffer)5_++vPFPhfunction push(valaue, buffer)5_++vPFQhfunction push(value, buffer)5_++vPFQhfunction push(value, buffer) {}5_,,vPFTj i5_--vPFVj buffer.push()5_--vPFXk j5_..vPFZk5_<//vPF^lE accumulate(input, function(value) { buffered.push(input) }, buffer)5_ //vPFhl! accumulate(input, push, buffer)5_//vPFklfunction push(value, buffer) {5_vPFpl buffer.push(value)5_vPFsl return buffer5_ vPFm l5_vPFm var result = concat()5_&vPG m' var result = concat(buffered, result)5_vPGJm reduce(input, next, initial)5_"vPGTn m5_vPGVn if ()5_vPG[n if (buffered.[])5_vPG\n if (buffered[])5_vPG`n if (buffered[buffer.length])5_vPGfn if (buffered.indexOf())5_vPGjn if (buffered.indexOf(null))5_ vPGwn$ if (buffered.indexOf(null) => 0)5_ vPGzn# if (buffered.indexOf(null) > 0)5_$vPG{n$ if (buffered.indexOf(null) >= 0)5_,vPGn- if (buffered.indexOf(null) >= 0) reduce()5_vPGn5 if (buffered.indexOf(null) >= 0) reduce(buffered)5_vPGn< return if (buffered.indexOf(null) >= 0) reduce(buffered)5_'vPGn8 return buffered.indexOf(null) >= 0) reduce(buffered)5_vPGn! reduce(result, next, initial)5_&vPGnE : reduce(result, next, initial)5_8vPGn9 return buffered.indexOf(null) >= 0 ? reduce(buffered)5_vPGon5_vPGovar concat = require()5_vPGovar concat = require("")5_vPG"var convert = require("./convert")5_vPG5_vPG"var queued = "queued@" + module.id5_  vPG$var forward = "forward@" + module.id5_  vPG var state = "state@" + module.id5_  vPG var input = "input@" + module.id5_  vPG5_  vPGvar into = required("./into")5_evPGgP&function drain(buffer, next, result) { var values = buffer[queued]= while (values.length) result = next(values.shift(), result) buffer[queued] = null return result}function isDrained(buffer) { return buffer[queued] === null}function Buffer() { this[state] = null this[queued] = [] this[input] = []}4Buffer.prototype.forward = function forward(value) { this.queued.push(value)};accumulate.define(Buffer, function(buffer, next, initial) {L // If buffer has already been drained accumulate from the original source.H if (isDrained(buffer)) return accumulate(buffer[input], next, initial)M // Otherwise, drain the buffer, passing items to the accumulating function.. buffer[state] = drain(buffer, next, initial)/ // Overshadow forward function, insuring thatK // future values are not buffered, and are instead passed directly to the // accumulation function. buffer[forward] = next return buffer})function buffer(source) { /**L Buffer a reducible, saving items from reducible in-memory until a consumer reduces the buffer.N Reducibles are not required to expose a data container for the sequence theyL represent, meaning items in the reducible may not be represented in-memoryM at all. This is great for representing potentially infinite data structuresI like "mouse clicks over time", or "data streamed from server". However,L sometimes it's important to reduce all items in the reducible, even if theO item was emitted at a point in the past. This is where buffer comes in handy.H It stores a backlog of previously emitted items in-memory until you're ready to consume. **/1 var value = reducible(function(next, initial) {N // If buffer has already been drained accumulate from the original source.> if (isDrained(value)) return reduce(source, next, initial)O // Otherwise, drain the buffer, passing items to the accumulating function.. value[state] = drain(value, next, initial)1 // Overshadow forward function, insuring thatM // future values are not buffered, and are instead passed directly to the // accumulation function. value[forward] = next return buffer }) value[state] = null buffer[input] = source self[queued] = []# self[forward] = function(value) { self[queued].push(value) }& accumulate(source, function(value) {3 self[state] = self[forward](value, self[state]) }) return self}5buffer.accumulate = function(buffer, next, initial) {L // If buffer has already been drained accumulate from the original source.H if (isDrained(buffer)) return accumulate(buffer[input], next, initial)M // Otherwise, drain the buffer, passing items to the accumulating function.. buffer[state] = drain(buffer, next, initial)/ // Overshadow forward function, insuring thatK // future values are not buffered, and are instead passed directly to the // accumulation function. buffer[forward] = next return buffer}5_vPG5_vPHs5_vPHwvar hub = require()5_vPHwvar hub = require("")5_vPH 5_vPH var source = hub()5_%vPH& var result = concat(buffered, input)5_ vPH' var result = concat(buffered, source)5_vPH# accumulate(input, push, buffered)5_#vPH$ accumulate(source, push, buffered)5_#vPH 5_#vPH 5_##vPH5_#vPH' var result = concat(buffered, source)5_ %v%PH( var result = concat(buffered, source)5_ %v%PH5_ %v%PH 5_ %v%PI+ 5_ %v%PI. // Buffering5_ %v%PI;' // Create an array of buffered values5_/ %v%PI>/ // Create an array of already buffered values5_  %v%PIA  5_ %v%PID function isDrained()5_ %v%PIE function isDrained() {}5_ %v%PIJ function isDrained() {5_ %v%PIK  }5_ %v%PIW 5_ %v%PIb // Accumulate source 5_0 %v%PIc!0 // Create an array of already buffered values.5_# %v%PIz5_ %v%PI|5_ %v%PI // Result is 5_ %v%PI"# // If source is already drained, 5_$ %v%PI$ // If source has already drained, 5_5 %v%PI5 // If source has already drained, then use buffered5_@ %v%PIN // If source has already drained, then buffer contains `null` end of stream.5_P %v%PI#P // If source has already drained, then buffer contains `null` - end of stream.5_* %v%PI* // In that case result is just a buffer.5_+ %v%PI$+ // In that case result is just a buffer. 5_* %v%PI* // In that case result is just a buffer.5_+ %v%PI%+ // In that case result is just a buffer. 5_* %v%PJ$* // In that case result is just a buffer.5_   %v%PJ5& // buffered5_  8 %v%PJLP var result = buffered.indexOf(null) >= 0 ? buffered : concat(buffered, source)5_    %v%PJQP // If source has already drained, then buffer contains `null` - end of stream.5_    %v%PJRJ // In that case result is just a buffer, otherwise it's concatenation of5_    %v%PJT/ // buffered elements with rest of the source.5_   %v%PJU 5_  %v%PJ$ accumulate(source, push, buffered)5_" %v%PJ(" // Result is a concatenation of 5_; %v%PJ) 5_0 %v%PJ0 // otherwise reduce resulting concatenation.5_ %v%PJ  // sources.5_ %v%PJ+ H // otherwise reduce concatenation of buffered values and rest of thesource.  // source.5_ %v%PK   5_ %v%PK" * !5_E %v%PK/"E Function takes `input` sequence and starts buffering it internally.5_F %v%PK5"F Function takes `input` sequence and starts buffering it internally. 5_ = %v%PKA"= Function takes `input` sequence and returns equivalent sequ5_! J %v%PKP#J Function takes `input` sequence and returns equivalent sequence but with5_ "! %v%PKR# already buffered va5_!#" %v%PKh# So if `input` stream does 5_"$#B %v%PKz,#B So if `input` stream represents result of expensive computation 5_#%$ %v%PK$ buffered to do it only once.5_$&%. %v%PK$4 buffered to do it only once. Also note that buffer5_%'&5 %v%PK$5 buffered to do it only once. Also note that `buffer5_&('K %v%PK%K buffered to do it only once. Also note that `buffer` will start buffering5_')(6 %v%PK%K buffered to do it only once. Also note that `buffer` will start buffering5_(*)L %v%PK%[ buffered to do it only once. Also note that `buffer` is not lazy, it will start buffering5_)+*! !%v%PK& start bufferingsource & source 5_*,+ %v%PK-% start buffering source 5_+-,& %v%PK.%& start buffering `input` immediately.5_,.- %v%PK/%5_-/.Pצ'&5_.0/Pש'var end = require()5_/10Pת0'var end = require("")5_021" Pװ!#'H return buffered.indexOf(null) >= 0 ? reduce(buffered, next, initial)5_132#'P׳"$'F : reduce(result, next, initial)5_243 P׷!'K // If end of stream `null` is already in a buffer, then just reduce it,5_354 P׸!'L // If `end of stream `null` is already in a buffer, then just reduce it,5_465 !P׻1!'M // If `end` of stream `null` is already in a buffer, then just reduce it,5_576!IP2 #'P // otherwise reduce concatenation of buffered values and rest of the source.5_687#.P/"$(G return buffered.indexOf(end) >= 0 ? reduce(buffered, next, initial)5_798$.P53#%(E : reduce(result, next, initial)5_89P@4 var reduce = require("./reduce")5_  %v%PJm5_ %v%PJn'5_H %v%PJ~H return buffered.indexOf(null) >= 0 ? reduce(buffered, next, initial) 5_H %v%PJJ return buffered.indexOf(null) >= 0 ? reduce(buffered, next, initial) :5_I %v%PJ  result ? reduce()5_ %v%PJ1 result ? reduce(result, next, initial)5_ %v%PJF reduce(result, next, initial)5_vPH) //var result = concat(buffered, source)5_`ba==vPC5