https://github.com/Gozala/reducers
Tip revision: 97b3259cacf9e0c7268cb0efe92b67b560bdbc9f authored by Irakli Gozalishvili on 20 January 2013, 07:34:38 UTC
Remove dependency on phantomjs.
Remove dependency on phantomjs.
Tip revision: 97b3259
take-while.js
"use strict";
var reducer = require("./reducer")
var end = require("reducible/end")
var takeWhile = reducer(function takeWhile(predicate, next, value, result) {
/**
Returns a sequence of successive items from `source` while `predicate(item)`
returns `true`. `predicate` must be free of side-effects.
## Example
var digits = takeWhile([ 2, 7, 10, 23 ], function(x) { return x < 10 })
print(digits) // => < 2 7 >
**/
return predicate(value) ? next(value, result) :
// Predicate returned `false` just pass `end`. Reducer will take
// care of returning `reduced(result)` back.
next(end)
})
module.exports = takeWhile