tcomb-kefir
v0.0.1
Published
Tcomb types for Kefir observables
Downloads
4
Maintainers
Readme
tcomb-kefir
tcomb-kefir
provides Tcomb type combinators for
Kefir streams and properties.
This allows you to create streams and properties that have typesafe values.
Example
Here we create a typesafe function greet
. It takes a string Tcomb.Str
and returns a stream of
strings TcombKefir.stream(Tcomb.Str)
.
var Tcomb = require('tcomb'),
Kefir = require('kefir'),
TcombKefir = require('./src/tcomb-kefir'),
readline = require('readline'),
greet = Tcomb.func(Tcomb.Str, TcombKefir.stream(Tcomb.Str))
.of(function(greeting) {
var rlInterface = readline.createInterface({ input: process.stdin, output: process.stdout }),
question = "What would you like to be called? ",
ask = function(callback) { rlInterface.question(question, callback) },
answer = Kefir.fromCallback(ask),
append = function(name) { return greeting + " " + name + "!"; };
return answer.map(append).onValue(rlInterface.close.bind(rlInterface));
});
greet("Hi there").onValue(console.log.bind(console));