Skip to content

Create a new stream that passes all values through a function and forwards them to a target stream.

License

Notifications You must be signed in to change notification settings

paldepind/flyd-forwardto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flyd-forwardto

Create a new stream that passes all values through a function and forwards them to a target stream.

This function is inspired by the Elm function of the same name.

Signature

Stream b -> (a -> b) -> Stream a

Example

// We create a stream of numbers
var numbers = flyd.stream();
// And another stream that squares the numbers
var squaredNumbers = flyd.map(function(n) { return n*n; }, numbers);
// Add a logger just for show
flyd.map(function(n) { console.log(n); }, squaredNumbers);
// For some reason we have a lot of string of numbers, but we can't
// send them down the `numbers` stream. That would wreck havoc in the
// squaring function. `forwardTo` to the resque!
var stringNumbers = forwardTo(numbers, parseInt);
stringNumbers('7'); // `49` is logged

About

Create a new stream that passes all values through a function and forwards them to a target stream.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published