https://github.com/Gozala/reducers
Raw File
Tip revision: 38a5e8acba430b42f4e74e7c13c624e93d5deecd authored by Irakli Gozalishvili on 29 October 2012, 03:08:09 UTC
Version 0.2.0
Tip revision: 38a5e8a
convert.js
"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 ]
  **/
  var base = typeof(source) === "object" ? make(source) : {}
  return accumulate.implement(base, method)
}

module.exports = convert
back to top