-
-
Save jdeebee/a6d7dfd72e3a3b4879647e25c16479c1 to your computer and use it in GitHub Desktop.
Functional Reactive Programming (FRP) with Bacon.js - example 1 - JS Bin source: http://jsbin.com/tebihizuke (slides here: http://ollimahlamaki.fi/baconjs-hubchat-tech-and-beer/#/1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> | |
<script src="https://rawgit.com/baconjs/bacon.js/master/dist/Bacon.js"></script> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// Bacon.sequentially gives the values in the array with a delay | |
// specified by the first parameter in ms | |
var originalStream = Bacon.sequentially(100, [1, -6, -24, 666]) | |
originalStream.log("Original") | |
// Create a stream with every number increased by 20 | |
var increasedStream = originalStream.map(function(x) {return x*20}) | |
increasedStream.log("Increased") | |
// Create a stream with only the positive numbers of originalStream | |
var positiveStream = originalStream.filter(function(x) {if (x>0) return x}) | |
positiveStream.log("Positive") | |
// Create a stream which tell if the numbers in originalStream are positive (true) or negative(false) | |
var signStream = originalStream.map(function(x) {x>0}) | |
signStream.log("Sign") | |
// Combine .map and .filter to make your own streams | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// Bacon.sequentially gives the values in the array with a delay | |
// specified by the first parameter in ms | |
var originalStream = Bacon.sequentially(100, [1, -6, -24, 666]) | |
originalStream.log("Original") | |
// Create a stream with every number increased by 20 | |
var increasedStream = originalStream.map(function(x) {return x*20}) | |
increasedStream.log("Increased") | |
// Create a stream with only the positive numbers of originalStream | |
var positiveStream = originalStream.filter(function(x) {if (x>0) return x}) | |
positiveStream.log("Positive") | |
// Create a stream which tell if the numbers in originalStream are positive (true) or negative(false) | |
var signStream = originalStream.map(function(x) {x>0}) | |
signStream.log("Sign") | |
// Combine .map and .filter to make your own streams</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bacon.sequentially gives the values in the array with a delay | |
// specified by the first parameter in ms | |
var originalStream = Bacon.sequentially(100, [1, -6, -24, 666]) | |
originalStream.log("Original") | |
// Create a stream with every number increased by 20 | |
var increasedStream = originalStream.map(function(x) {return x*20}) | |
increasedStream.log("Increased") | |
// Create a stream with only the positive numbers of originalStream | |
var positiveStream = originalStream.filter(function(x) {if (x>0) return x}) | |
positiveStream.log("Positive") | |
// Create a stream which tell if the numbers in originalStream are positive (true) or negative(false) | |
var signStream = originalStream.map(function(x) {x>0}) | |
signStream.log("Sign") | |
// Combine .map and .filter to make your own streams |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Functional Reactive Programming (FRP) with Bacon.js - example 0