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
fs=require "fs" | |
Bacon=require "baconjs" | |
Bacon.watchFile = (filename) -> | |
Bacon.fromBinder (sink) ->· | |
w = fs.watch filename, sink | |
-> w.close() | |
Bacon.watchFile("lol.txt").log() |
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
module PrincessVsLion where | |
import Keyboard | |
-- character positions | |
princess = foldp inc 4 (pressesOf Keyboard.space) | |
lion = foldp inc 0 (fps 2) | |
-- combined game state | |
gameState = lift2 makeState princess lion |
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.Observable.prototype.logWithTimestamp = function() { | |
var args = Array.prototype.slice.call(arguments, 0) | |
this.onValue(function(value) { | |
console.log.apply(console, [new Date().getTime()].concat(args.concat([value]))) | |
}) | |
return this | |
} |
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
function requireInOrder(paths, done) { | |
if (paths.length == 0) { | |
done() | |
} else { | |
require(paths.slice(0,1), function() { | |
requireInOrder(paths.slice(1), done) | |
}) | |
} | |
} |
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
fs = require("fs") | |
Bacon = require("baconjs") | |
# Bacon.fromNodeStream converts Node.js ReadableStream into an EventStream | |
Bacon.fromNodeStream = (stream) -> | |
Bacon.fromBinder (sink) -> | |
listeners = {} | |
addListener = (event, listener) -> | |
listeners[event] = listener | |
stream.on event, listener |
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
import Keyboard | |
import Window | |
startPos = {x = 10, y = 10} | |
startDir = {x = 1, y = 0} | |
dir = foldp rotate startDir Keyboard.arrows | |
rotateLeft p = {x=p.y * (0-1), y=p.x} | |
rotateRight p = {x=p.y, y=p.x * (0-1)} | |
rotate dir p = if | dir.x < 0 -> rotateLeft p | |
| dir.x > 0 -> rotateRight p |
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
'use strict'; | |
var $ = require('jquery2'); | |
var Bacon = require('baconjs'); | |
$.fn.asEventStream = Bacon.$.asEventStream; | |
var _ = require('lodash'); | |
// Input events | |
var mouseDownE = $(document).asEventStream('mousedown'), | |
mouseUpE = $(document).asEventStream('mouseup') |
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
'use strict'; | |
var $ = require('jquery2'); | |
var Bacon = require('baconjs'); | |
$.fn.asEventStream = Bacon.$.asEventStream; | |
var _ = require('lodash'); | |
// Input events | |
var mouseDownE = $(document).asEventStream('mousedown'), | |
mouseUpE = $(document).asEventStream('mouseup') |
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.Observable.prototype.fold = function(seed, f) { | |
var scanned = this.scan(seed, f) | |
return scanned.changes().mapEnd().map(scanned) | |
} |
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
let jsarray xs = | |
let plusOne = Array.prototype.concat.apply [1] xs | |
let jsarr = Array.apply null plusOne | |
jsarr.slice 1 | |
let always x = (\() -> x) | |
let length xs = (jsarray xs).length | |
let empty xs = (length xs) == 0 | |
let concat xs ys = (jsarray xs).concat ys | |
let cons x xs = concat [x] xs |