reduce: Throw TypeError if the channel contains no values and initialValue is not provided.

This commit is contained in:
David Braun 2017-10-13 21:32:27 -04:00
parent 7d0d203c2e
commit ecc01b686e
No known key found for this signature in database
GPG key ID: 5694EEC4D129BDCF
3 changed files with 77 additions and 54 deletions

View file

@ -182,14 +182,20 @@ const Channel = function (bufferLength = 0) {
await readOnly.forEach((currentValue) => {
if (previousValueDefined) {
previousValue = callbackfn(previousValue, currentValue, 0, readOnly)
previousValue = callbackfn(previousValue, currentValue)
} else {
previousValue = currentValue
previousValueDefined = true
}
})
return previousValue
if (previousValueDefined) {
return previousValue
} else {
throw new TypeError(
`No values in channel and initialValue wasn't provided.`
)
}
},
shift: function () {