https://github.com/Gozala/reducers
Tip revision: edf8ee8f4e5208bb19e7bd4d02393288aa3aef1d authored by Irakli Gozalishvili on 21 October 2012, 07:27:11 UTC
Version 0.1.0
Version 0.1.0
Tip revision: edf8ee8
convert.js
/*jshint asi: true undef: true es5: true node: true browser: true devel: true
forin: true latedef: false globalstrict: true */
"use strict";
var accumulate = require("./accumulate")
var make = Object.create || (function() {
function Type() {}
return function make(prototype) {
Type.prototype = prototype
return new Type()
}
})()
function convert(source, method) {
/**
Function takes `source` sequence and returns new `sequence` such
that calling `accumulate` on it will delegate to given `method`.
This is to make sequence conversions lazy.
// Code will produce sequence that is just like `source` but with
// each element being incremented.
function increment(source) {
return convert(source, function(sequence, f, start) {
return accumulate(source, function(value, result) {
return f(value + 1, result)
}, start)
})
}
into(increment([ 1, 2, 3 ])) => [ 2, 3, 4 ]
**/
return accumulate.implement(make(source), method)
}
module.exports = convert