Skip to content

Instantly share code, notes, and snippets.

@Raynos Raynos/accumulate.js Secret
Last active Dec 15, 2015

Embed
What would you like to do?
var foldp = require("signal/foldp")
var merge = require("signal/merge")
// accumulate :: [Signal<Function(S -> S)>] -> S -> Signal<S>
module.exports = accumulate
// accumulate take a list of signals of functions that take previous
// state and returns some new state and also takes the initial
// state. It will return a signal of the current state as applied
// by those functions
function accumulate(args, initial) {
return foldp(merge(args), function (state, fn) {
return fn(state)
}, initial)
}
// Signal :: Observable (dominictarr/observable)
// signals at the implementation detail are just observables
// for our case we use them as a value over time abstraction
// inspect :: Signal -> DOMElement
// inspect takes a signal and returns a dom element that will
// render the value of the signal in it's textContent
var inspect = require("../../signal/inspect")
// merge :: [Signal] -> Signal
// Takes a list of signals and returns a signal whoms current
// value is the last updated value of all the signals.
// merge is like Array.prototype.concat
var merge = require("../../signal/merge")
// foldp :: Signal<T> -> (S -> T -> S) -> S -> Signal<S>
// Folder :: function(S state, T value) return S newState
// foldp :: function(Signal<T> input, Function::Folder folder, S initial) return Signal<S>
// foldp takes a signal, transform function and an initial state
// it then calls your function with (state, valueOfSignal).
// the value you return from that function will become the new
// state of the returned signal
// foldp is like Array.prototype.reduce
var foldp = require("../../signal/foldp")
// transform :: Signal<A> -> (A -> B) -> Signal<B>
// transform takes a signal and a lambda. The returned signal will
// contain all the values of the original signal except your
// lambda will be called on those values. i.e. it just transforms
// the signal, one value at a time.
// transform is like Array.prototype.map
var transform = require("../../signal/transform")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.