Skip to content

Instantly share code, notes, and snippets.

@jdeebee
Forked from anonymous/index.html
Last active May 28, 2016 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdeebee/a6d7dfd72e3a3b4879647e25c16479c1 to your computer and use it in GitHub Desktop.
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)
<!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>
// 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
@jdeebee
Copy link
Author

jdeebee commented May 28, 2016

Functional Reactive Programming (FRP) with Bacon.js - example 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment