Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created June 6, 2014 19:13
Show Gist options
  • Save Raynos/9b7e3848977a6f640450 to your computer and use it in GitHub Desktop.
Save Raynos/9b7e3848977a6f640450 to your computer and use it in GitHub Desktop.
var Observ = require('observ');
/* flatMap := (Observ<T>, (T) => Observ<S>) => Observ<S>
*/
function flatMap(observ, fn) {
var v = fn(observ());
var result = Observ(v());
v(result.set);
observ(function (t) {
v = fn(t);
result.set(v());
v(result.set);
});
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment